A106665 Alternate paper-folding (or alternate dragon curve) sequence.
1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1
Offset: 0
Examples
1 + x^3 + x^4 + x^5 + x^8 + x^12 + x^13 + x^15 + x^16 + x^19 + x^20 + ...
References
- M. Gardner, "The Dragon Curve and Other Problems (Mathematical Games)", Scientific American, 1967, columns for March, April, July.
- M. Gardner, "Mathematical Magic Show" (contains the dragon curve columns).
- D. E. Knuth, "Art of Computer Programming," vol. 2, 3rd. ed., "Seminumerical > Algorithms," (section 4.1)
Links
- Joerg Arndt, Matters Computational (The Fxtbook), section 1.31.3.2 "The alternate paper-folding sequence", pp. 90-92
- Chandler Davis and Donald E. Knuth, Number Representations and Dragon Curves - II, Journal of Recreational Mathematics, Vol. 3, No. 3, 1970, pp. 133-149, see section 4. Reprinted in Donald E. Knuth, Selected Papers on Fun and Games, 2011, pages 571-614.
- Chandler Davis and Donald E. Knuth, Number Representations and Dragon Curves, Journal of Recreational Mathematics, volume 3, number 2, April 1970, pages 66-81, and number 3, July 1970, pages 133-149. [Cached copy, with permission]
- William J. Gilbert, Fractal geometry derived from complex bases, The Mathematical Intelligencer, Volume 4, Number 2 (June 1982), pp. 78-86. (ISSN 0343-6993; DOI 10.1007/BF03023486)
- Kevin Ryde, Iterations of the Alternate Paperfolding Curve, see index "TurnLpred" with a(n) = TurnLpred(n+1).
- Wikipedia, Dragon curve
Programs
-
Maple
a:= proc(n) option remember; `if`(irem(n, 4)=0, 1, `if`(irem(n, 2)=1, 1-a((n-1)/2), 0)) end: seq(a(n), n=0..120); # Alois P. Heinz, Mar 10 2012
-
Mathematica
a[n_] := a[n] = Switch[Mod[n, 4], 0, 1, 2, 0, _, 1-a[(n-1)/2]]; Table[a[n], {n, 0, 120}] (* Jean-François Alcover, Mar 15 2017 *)
-
PARI
{a(n) = n++; if( n==0, 0, v = valuation( n, 2); (n/2^v\2 + v+1) %2 )} /* Michael Somos, Mar 10 2012 */
-
Python
def A106665(n): return ((n+1>>(m:=(~(n+1)&n).bit_length()))+1>>1)+m&1 # Chai Wah Wu, Feb 25 2025
Formula
For n >= 0, a(4n) = 1, a(4n+2) = 0, a(2n+1) = 1 - a(n).
-(-1)^a(n) = A209615(n+1). - Michael Somos, Mar 10 2012
G.f.: 1/(1 - x^4) + Sum_{k>=1} x^(2*((-1 - (-2)^(k - 1)) mod 2^(k + 1)) + 1)/(1 - x^(2^(k + 2))). - Miles Wilson, Nov 18 2024
Extensions
Edited by N. J. A. Sloane, Jun 04 2010 to include material from discussions on the Sequence Fans Mailing List.
Comments