cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

User: Bill Blewett

Bill Blewett's wiki page.

Bill Blewett has authored 5 sequences.

A178715 a(n) = solution to the "Select All, Copy, Paste" problem: Given the ability to type a single letter, or to type individual "Select All", "Copy" or "Paste" command keystrokes, what is the maximal number of letters of text that can be obtained with n keystrokes?

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 9, 12, 16, 20, 27, 36, 48, 64, 81, 108, 144, 192, 256, 324, 432, 576, 768, 1024, 1296, 1728, 2304, 3072, 4096, 5184, 6912, 9216, 12288, 16384, 20736, 27648, 36864, 49152, 65536, 82944, 110592, 147456, 196608, 262144, 331776, 442368, 589824, 786432, 1048576, 1327104, 1769472, 2359296, 3145728, 4194304
Offset: 1

Author

Bill Blewett, Jan 11 2011

Keywords

Comments

It is assumed that we start with a single letter in the copy buffer.
Alternatively, a(n-1) = maximal value of Product (k_i-1) for any way of writing n = Sum k_i.
1. The description above assumes that the text is deselected after the Copy command is invoked.
2. This sequence is the solution to the equivalent problem formulated as {insert, "Select All+ Copy" macro (without deselection), Paste}.
3. This sequence is a "paradigm-shift" sequence with procedure length p =1 (in the sense of A193455).
4. The optimal number of pastes per copy, as measured by the geometric growth rate (p+z root of z), is z = 4. [noninteger maximum between 3 and 4]
5. The function a(n) = maximum value of the product of the terms k_i, where Sum (k_i) = n+1-i_max.
6. All solutions will be of the form a(n) = m^b * (m+1)^d.

Examples

			For n = 7 the a(7) = 9 solution is to type the seven keystrokes: paste, paste, paste, select-all, copy, paste paste which yields nine text characters.
Here is a table showing the pattern for n = 1 to 35. The first column is n and the second column is the number of characters that can be obtained with n keystrokes.  The remainder of the line shows how to get the maximum, as follows.  S = Select and C = Copy while a dot stands for Paste.  The dots at the beginning of a line are equivalent to a single letter being typed, based on the assumption that at the start there is a single letter in the paste buffer.
01: 00001 .
02: 00002 ..
03: 00003 ...
04: 00004 ....
05: 00005 .....
06: 00006 ......
07: 00009 ...SC..
08: 00012 ....SC..
09: 00016 ....SC...
10: 00020 .....SC...
11: 00027 ...SC..SC..
12: 00036 ....SC..SC..
13: 00048 ....SC...SC..
14: 00064 ....SC...SC...
15: 00081 ...SC..SC..SC..
16: 00108 ....SC..SC..SC..
17: 00144 ....SC...SC..SC..
18: 00192 ....SC...SC...SC..
19: 00256 ....SC...SC...SC...
20: 00324 ....SC..SC..SC..SC..
21: 00432 ....SC...SC..SC..SC..
22: 00576 ....SC...SC...SC..SC..
23: 00768 ....SC...SC...SC...SC..
24: 01024 ....SC...SC...SC...SC...
25: 01296 ....SC...SC..SC..SC..SC..
26: 01728 ....SC...SC...SC..SC..SC..
27: 02304 ....SC...SC...SC...SC..SC..
28: 03072 ....SC...SC...SC...SC...SC..
29: 04096 ....SC...SC...SC...SC...SC...
30: 05184 ....SC...SC...SC..SC..SC..SC..
31: 06912 ....SC...SC...SC...SC..SC..SC..
32: 09216 ....SC...SC...SC...SC...SC..SC..
33: 12288 ....SC...SC...SC...SC...SC...SC..
34: 16384 ....SC...SC...SC...SC...SC...SC...
35: 20736 ....SC...SC...SC...SC..SC..SC..SC..
It appears that A000792 is the result if only one keystroke instead of two is required for the "Select All, Copy" operation.  Here is the table.  Here "C" means that all the previously typed characters are copied to the paste buffer.
01: 00001 .
02: 00002 ..
03: 00003 ...
04: 00004 ....
05: 00006 ...C.
06: 00009 ...C..
07: 00012 ....C..
08: 00018 ...C..C.
09: 00027 ...C..C..
10: 00036 ....C..C..
11: 00054 ...C..C..C.
12: 00081 ...C..C..C..
13: 00108 ....C..C..C..
14: 00162 ...C..C..C..C.
15: 00243 ...C..C..C..C..
16: 00324 ....C..C..C..C..
17: 00486 ...C..C..C..C..C.
18: 00729 ...C..C..C..C..C..
19: 00972 ....C..C..C..C..C..
20: 01458 ...C..C..C..C..C..C.
21: 02187 ...C..C..C..C..C..C..
22: 02916 ....C..C..C..C..C..C..
23: 04374 ...C..C..C..C..C..C..C.
24: 06561 ...C..C..C..C..C..C..C..
25: 08748 ....C..C..C..C..C..C..C..
26: 13122 ...C..C..C..C..C..C..C..C.
27: 19683 ...C..C..C..C..C..C..C..C..
28: 26244 ....C..C..C..C..C..C..C..C..
29: 39366 ...C..C..C..C..C..C..C..C..C.
30: 59049 ...C..C..C..C..C..C..C..C..C..
31: 78732 ....C..C..C..C..C..C..C..C..C..
		

Crossrefs

See A193286 for another version. Cf. A000792.
A000792, A178715, A193286, A193455, A193456, and A193457 are paradigm shift sequences with procedure lengths p=0,1,...,5, respectively.
Cf. A367116 (squares summing to n).

Programs

  • Mathematica
    LinearRecurrence[{0,0,0,0,4},{1,2,3,4,5,6,9,12,16,20,27,36,48,64,81},60] (* Harvey P. Dale, Apr 11 2017 *)
  • PARI
    Vec(x*(1 +2*x +3*x^2 +4*x^3 +5*x^4 +2*x^5 +x^6 +3*x^10 +x^14) / (1 -4*x^5) + O(x^100)) \\ Colin Barker, Nov 19 2016
    
  • Python
    def a(n):
        c=(n//5) + 1
        if n<15:
            if n==5: return 5
            if n==10: return 20
            r=(n + 1)%c
            q=((n + 1)//c) - 1
            return q**(c - r)*(q + 1)**r
        else:
            r=n%5
            return 3**(4 - r)*4**(c - 4 + r)
    print([a(n) for n in range(1, 102)]) # Indranil Ghosh, Jun 27 2017

Formula

a(n) = 4*a(n-5) for n>=16.
a(n) =
a(5;10) = 5; 20 [C=1, 2 below, respectively]
a(n=1:14) = Q^(C-R)*(Q+1)^R
where C = floor(n/5)+1, R = n+1 mod C,
and Q = floor(n+1/C)-1
a(n>=15) = 3^(4-R)*4^(C-4+R)
where C = floor (n/5)+1, R = n mod 5.
G.f.: x*(1 +2*x +3*x^2 +4*x^3 +5*x^4 +2*x^5 +x^6 +3*x^10 +x^14) / (1 -4*x^5). - Colin Barker, Nov 19 2016

Extensions

Edited by N. J. A. Sloane, Jul 21 2011
Additional comment and formula from David Applegate, Jul 21 2011
Additional comments, formulas, and CrossRefs by Jonathan T. Rowell, Jul 30 2011
More terms from Joerg Arndt, Nov 15 2014

A129700 Number of n-step self-avoiding paths on octant grid starting at octant origin.

Original entry on oeis.org

1, 1, 2, 3, 8, 14, 36, 70, 177, 372, 942, 2056, 5222, 11736, 29878, 68576, 175038, 408328, 1044533, 2468261, 6326688, 15107015, 38791865, 93432564, 240296399, 583001850, 1501520574, 3665682736, 9452895693, 23201772603, 59899677902
Offset: 1

Author

Bill Blewett, Jun 01 2007

Keywords

Comments

Similar to A038373 but with octant grid instead of quadrant. An octant grid is either half of a quadrant grid when divided on the diagonal and including the diagonal grid squares. Its shape is that of a right triangle with a stair step edge on the hypotenuse. Coordinates of squares satisfy x>=0 and y>=0 and x>=y.
Guttmann-Torrie series coefficients c_n^2 for square lattice, with wedge angle Pi/4. - N. J. A. Sloane, Jul 06 2015

Crossrefs

Cf. A038373.

Programs

  • C
    #include 
    #include 
    #define GRIDSIZE 20
    void Recur(int level, int maxlevel, int rgBd[][GRIDSIZE], int i, int j, int rgCt[]) {
      if (i < 0 || j < 0 || i >= GRIDSIZE || j >= GRIDSIZE || level >= maxlevel || j > i || rgBd[i][j] != 0) return;
      rgCt[level] += 1;
      rgBd[i][j] = 1;
      Recur(level + 1, maxlevel, rgBd, i + 1, j, rgCt);
      Recur(level + 1, maxlevel, rgBd, i - 1, j, rgCt);
      Recur(level + 1, maxlevel, rgBd, i, j + 1, rgCt);
      Recur(level + 1, maxlevel, rgBd, i, j - 1, rgCt);
      rgBd[i][j] = 0;
    }
    int main(int argc, char **argv) {
      int rgBd[GRIDSIZE][GRIDSIZE] = {0};
      int rgCt[GRIDSIZE] = {0};
      int maxlevel = GRIDSIZE;
      if (argc > 1) {
        maxlevel = atoi(argv[1]);
        if (maxlevel < 0 || maxlevel > GRIDSIZE) {
          printf("Bad argument");
          return 0;
        }
      }
      Recur(0, maxlevel, rgBd, 0, 0, rgCt);
      for (int i = 0; i < maxlevel; i++) printf("%2d ", rgCt[i]);
      return 0;
    }

Extensions

a(28)-a(31) from Sean A. Irvine, Jul 03 2021

A107427 Maximal number of simple triangular regions that can be formed by drawing n line segments in the Euclidean plane.

Original entry on oeis.org

0, 0, 1, 2, 4, 7, 10, 14, 18, 22
Offset: 1

Author

Bill Blewett, May 22 2005

Keywords

Comments

Draw n line segments on a piece of paper in such a way that if we make cuts along those lines, only triangular pieces are formed (apart from the "outside" region). Sequence gives maximal number of triangles that can be obtained.
Inspection of Loy's web page shows that these are known to be optimal only for n up to about 7.
Loy gives the following lower bounds for n = 1, 2, 3, ...: 0, 0, 1, 2, 4, 7, 10, 14, 18, 22, 27, 32, 38, 44, 50, 54, 60, 72, 76, 84, 92, 110, 114, 122, 130, 156, 160, 210

Examples

			7 lines can make at most 10 triangles, so a(7) = 10.
		

Crossrefs

Cf. A000124.

Extensions

Entry revised by N. J. A. Sloane, May 29 2005

A000376 Topswops (2): start by shuffling n cards labeled 1..n. If the top card is m, reverse the order of the top m cards. Repeat until 1 gets to the top, then stop. Suppose the whole deck is now sorted (if not, discard this case). a(n) is the maximal number of steps before 1 got to the top.

Original entry on oeis.org

0, 1, 2, 4, 7, 10, 16, 22, 30, 38, 51, 63, 80, 101, 112, 130, 159, 191, 207, 231
Offset: 1

Author

Bill Blewett, Mike Toepke [ mtoepke(AT)microsoft.com ]

Keywords

Comments

See also A000375, which is the main entry for this problem.
Comments from Joshua Zucker, Jan 24 2007: (Start)
For some n, there are some longest chains which end up sorted and some which don't, like n = 6, with the following four chains that end sorted and one that does not:
The examples below use 0 through n-1 instead of 1 through n.
((#(4 5 3 0 2 1) #(2 0 3 5 4 1) #(3 0 2 5 4 1) #(5 2 0 3 4 1) #(1 4 3 0 2 5) #(4 1 3 0 2 5) #(2 0 3 1 4 5) #(3 0 2 1 4 5) #(1 2 0 3 4 5) #(2 1 0 3 4 5) #(0 1 2 3 4 5))
(#(3 4 5 1 0 2) #(1 5 4 3 0 2) #(5 1 4 3 0 2) #(2 0 3 4 1 5) #(3 0 2 4 1 5) #(4 2 0 3 1 5) #(1 3 0 2 4 5) #(3 1 0 2 4 5) #(2 0 1 3 4 5) #(1 0 2 3 4 5) #(0 1 2 3 4 5))
(#(3 0 4 1 5 2) #(1 4 0 3 5 2) #(4 1 0 3 5 2) #(5 3 0 1 4 2) #(2 4 1 0 3 5) #(1 4 2 0 3 5) #(4 1 2 0 3 5) #(3 0 2 1 4 5) #(1 2 0 3 4 5) #(2 1 0 3 4 5) #(0 1 2 3 4 5))
(#(2 5 4 0 3 1) #(4 5 2 0 3 1) #(3 0 2 5 4 1) #(5 2 0 3 4 1) #(1 4 3 0 2 5) #(4 1 3 0 2 5) #(2 0 3 1 4 5) #(3 0 2 1 4 5) #(1 2 0 3 4 5) #(2 1 0 3 4 5) #(0 1 2 3 4 5)))
(#(3 0 5 4 1 2) #(4 5 0 3 1 2) #(1 3 0 5 4 2) #(3 1 0 5 4 2) #(5 0 1 3 4 2) #(2 4 3 1 0 5) #(3 4 2 1 0 5) #(1 2 4 3 0 5) #(2 1 4 3 0 5) #(4 1 2 3 0 5) #(0 3 2 1 4 5))
And for some n, e.g., n=12, none of the longest chains end up sorted (and hence A000375 and A000376 are different). I did an exhaustive search with n = 12 working backwards from sorted and found 63 as the longest chain beginning with one of these four:
#(9 10 6 0 2 7 1 8 11 5 3 4)
#(9 10 6 0 1 2 7 8 11 5 3 4)
#(7 8 11 5 0 6 10 9 2 1 3 4)
#(5 0 1 7 10 3 11 8 9 6 2 4)
But 65 is attainable if you don't assume it ends up sorted. (End)
Comment from Quan T. Nguyen, William Fahle (tuongquan.nguyen(AT)utdallas.edu), Oct 21 2010: (Start)
(6 14 9 2 15 8 1 3 4 12 18 5 10 13 16 17 11 7) is the only permutation of length 18 that takes 191 steps (also called longest-winded permutation) of "topswopping moves" before it goes to the identity permutation (i.e., in sorted order).
For n=17, (2 10 15 11 7 14 5 16 6 4 17 13 1 3 8 9 12) is the only longest-winded permutation (or order of cards) that takes 159 steps of "topswopping moves" before it terminates in sorted order, i.e., (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17). (End)
Comment from Moritz Franckenstein, Apr 16 2011: (Start)
n=18 -> 191
6 14 9 2 15 8 1 3 4 12 18 5 10 13 16 17 11 7
n=19 -> 207
2 3 7 8 4 19 10 15 17 6 1 11 5 18 12 9 13 14 16
3 7 2 8 4 19 10 15 17 6 1 11 5 18 12 9 13 14 16
n=20 -> 231
5 20 6 3 2 15 10 1 16 9 18 14 19 7 12 17 8 11 13 4
3 20 5 6 2 15 10 1 16 9 18 14 19 7 12 17 8 11 13 4
5 20 2 6 3 15 10 1 16 9 18 14 19 7 12 17 8 11 13 4 (End)

References

  • D. E. Knuth, TAOCP, Section 7.2.1.2, Problems 107-109.

Crossrefs

Programs

  • Python
    def a(n): # see A000375 for ts
      return max(ts(d, var=2) for d in P(range(1, n+1)))
    print([a(n) for n in range(1, 11)]) # Michael S. Branicky, Dec 11 2020

Extensions

a(14)-a(15) from James Kilfiger (mapdn(AT)csv.warwick.ac.uk), Jul 1997
a(16)-a(17) from William Rex Marshall, Mar 28 2001
Definition clarified by Franklin T. Adams-Watters, Jan 24 2007
a(18) from Quan T. Nguyen, William Fahle (tuongquan.nguyen(AT)utdallas.edu), Oct 21 2010
a(1)=0 prepended by Max Alekseyev, Nov 18 2010
a(19) from Moritz Franckenstein, Dec 14 2010
a(20) from Moritz Franckenstein, Apr 16 2011

A000375 Topswops (1): start by shuffling n cards labeled 1..n. If top card is m, reverse order of top m cards, then repeat. a(n) is the maximal number of steps before top card is 1.

Original entry on oeis.org

0, 1, 2, 4, 7, 10, 16, 22, 30, 38, 51, 65, 80, 101, 113, 139, 159, 191, 221
Offset: 1

Author

Bill Blewett and Mike Toepke [mtoepke(AT)microsoft.com]

Keywords

Comments

Knuth's algorithm can be extended by considering unsorted large unmovable segments: xxx645, e.g. will never move 6, 4, or 5. - Quan T. Nguyen, William Fahle (waf013000(AT)utdallas.edu), Oct 12 2010
For n=17, there are two longest-winded permutations (or orders of cards) that take 159 steps of "topswopping moves" before the top card is 1. (8 15 17 13 9 4 6 3 2 12 16 14 11 5 10 1 7) terminates at (1 6 2 4 9 3 7 8 5 10 11 12 13 14 15 16 17), and (2 10 15 11 7 14 5 16 6 4 17 13 1 3 8 9 12) terminates in sorted order, i.e., (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17). - Quan T. Nguyen, William Fahle (tuongquan.nguyen(AT)utdallas.edu), Oct 21 2010
Lower bounds for the next terms are a(18)>=191, a(19)>=221, a(20)>=249, a(21)>=282, a(22)>=335, a(23)>=382. - Hugo Pfoertner, May 21 2011; updated Oct 08 2016

Examples

			From _R. K. Guy_, Jan 24 2007: (Start)
With 4 cards there are just two permutations which require 4 flips:
3142 --> 4132 --> 2314 --> 3214 --> 1234
2413 --> 4213 --> 3124 --> 2134 --> 1234
In these cases the deck finishes up sorted. But this is not always the case - see A000376. (End)
		

References

  • Martin Gardner, Time Travel and Other Mathematical Bewilderments (Freeman, 1988), Chapter 6 "Combinatorial Card Problems" [based on a column that originally appeared in Scientific American, November 1974].
  • D. E. Knuth, TAOCP, Section 7.2.1.2, Problems 107-109.

Crossrefs

Cf. A000376 (a variation), A123398 (number of solutions).

Programs

  • Mathematica
    Table[Max@ Map[Length@ NestWhileList[Flatten@{Reverse@Take[#, First@ #], Take[#, -(Length@ # - First@ #)]} &, #, First@ # != 1 &] - 1 &, Permutations@ Range@ n], {n, 8}] (* Michael De Vlieger, Oct 08 2016 *)
  • PARI
    a(n)=my(s,t,v);for(i=1,n!,v=numtoperm(n,i);t=0;while(v[1]>1,v=if(v[1]Charles R Greathouse IV, Oct 14 2013
    
  • Python
    from itertools import permutations as P
    def ts(d, var=1): # algorithm VARiation
      s, m = 0, d[0]
      while m != 1:
        d = (d[:m])[::-1] + d[m:]
        s, m = s+1, d[0]
      if var==2: return s*(list(d)==sorted(d))
      return s
    def a(n):
      return max(ts(d) for d in P(range(1, n+1)))
    print([a(n) for n in range(1, 11)]) # Michael S. Branicky, Dec 11 2020

Extensions

One more term from James Kilfiger, Jul 1997
113 from William Rex Marshall, Mar 27 2001
139 from Don Knuth, Aug 25 2001
Added one new term by improved branch and bound using various new insights. - Quan T. Nguyen, William Fahle (waf013000(AT)utdallas.edu), Oct 12 2010
a(18)-a(19) from Kimura et al. added by Andrey Zabolotskiy, Mar 24 2021