A137695 Tower of Hanoi with p pegs: A(p,n) = number of moves needed for n disks, using Frame's or Stewart's algorithm, read by columns of the upper right triangle of rows p >= 3, columns n >= p-2.
1, 3, 3, 7, 5, 5, 15, 9, 7, 7, 31, 13, 11, 9, 9, 63, 17, 15, 13, 11, 11, 127, 25, 19, 17, 15, 13, 13, 255, 33, 23, 21, 19, 17, 15, 15, 511, 41, 27, 25, 23, 21, 19, 17, 17, 1023, 49, 31, 29, 27, 25, 23, 21, 19, 19, 2047, 65, 39, 33, 31, 29, 27, 25, 23, 21, 21, 4095, 81, 47, 37, 35
Offset: 1
Examples
The complete matrix would read (starting with row p = 3, column n = 1): 1_ 3 7 15 31 63 127 255 511 1023 ... 1 \_3_ 5 9 13 17 25 33 41 49 ... 1 3 \_5_ 7 11 15 19 23 27 31 ... 1 3 5 \_7_ 9 13 17 21 25 29 ... 1 3 5 7 \_9_ 11 15 19 23 27 ... 1 3 5 7 9 \_11_ 13 17 21 25 ... 1 3 5 7 9 11 \_13_ 15 19 23 ... 1 3 5 7 9 11 13 \_15_ 17 21 ... 1 3 5 7 9 11 13 15 \_17_ 19 ... _ (Since the columns become constant below the diagonal (symbolized by \_), we list only the part above it.) First row: 3 pegs, equals A000225; 2nd row: 4 pegs, cf. A007664; 3rd row: 5 pegs, cf. A007665.
References
- Sandi Klavžar and Uroš Milutinović. "Simple explicit formulas for the Frame-Stewart numbers." Annals of Combinatorics 6.2 (2002): 157-167; 0218-0006/02/020157-11. [This is an 11-page article. There is a free article on the web with the same authors and title, but which is only two pages long. - N. J. A. Sloane, Sep 10 2018]
Links
- M. F. Hasler, Table of n, a(n) for n = 1..1000, Apr 08 2025
- S. Klavzar et al., On the Frame-Stewart algorithm for the multi-peg Tower of Hanoi problem, Discrete Applied Mathematics 120 (2002) 141-15 and references therein.
Programs
-
Mathematica
s[n_, p_] := (k = 0; While[ n > Binomial[p - 3 + k++, p - 2] ] ; k - 2); x[n_, p_] := (snp = s[n, p]; Sum[2^t*Binomial[p - 3 + t, p - 3], {t, 0, snp - 1}] + 2^snp*(n - Binomial[p - 3 + snp, p - 2])); Flatten[Table[x[n, p], {n, 1, 12}, {p, 3, n + 2}] ] (* Jean-François Alcover, Jun 01 2011 *)
-
PARI
A137695(p, n=0/* if n=0, give p-th term of the "flat" sequence */)={n || p = 2+p+(1-n=1+sqrtint(2*p-2-sqrtint(2*p-2)))*n\2; if(p>n+1, 2*n-1, p==3, 2^n-1, my(s=1, t=0); while( n>binomial(p-2+t++,p-2), s+=2^t*binomial(p-3+t, p-3)); s+2^t*(n-binomial(p-3+t,p-2)))} \\ Edited by M. F. Hasler, Apr 08 2025
Formula
A(p,n) = Sum_{t=0..s-1} 2^t*binomial(p-3+t, p-3) + 2^s*(n-binomial(p-3+s, p-2)) where s = max { k in Z | n > binomial(p-3+k,p-2) }.
A(p,n) = 2n-1 if n > p+1, else 2^n-1 if p = 3, else see above. - M. F. Hasler, Apr 08 2025
Comments