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.
%I A308432 #48 Jun 22 2019 18:57:59 %S A308432 1,2,1,4,4,4,3,2,1,10,10,10,10,10,10,10,10,10,9,8,7,6,5,4,3,2,1,28,28, %T A308432 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28, %U A308432 28,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12 %N A308432 Given n cards in a stack numbered from 1 to n with 1 at the top, repeat the following process: first remove the card that is in the middle (at position (size of the stack)/2, rounding up), then move the card that is at the bottom of the stack to the top. This process is repeated until there is only one card left. a(n) is the number of the last remaining card. %C A308432 a(n) = 1 if n is a power of 3. %C A308432 a(n) = n if n-1 is a power of 3. %C A308432 From _Charlie Neder_, Jun 09 2019: (Start) %C A308432 Theorem: Formula below describes the sequence. %C A308432 Proof: a(n-1) gives the final card from a deck of size n-1, so a(n) will be equal to whichever card occupies the a(n-1)-th position after one iteration. If a(n-1) = 1, this will be card n, if a(n-1) <= ceiling(n/2), this will be card a(n-1)-1, and otherwise it will be card a(n-1). If a(3^k) = 1 (true for k = 0), then for this k: %C A308432 a(n) = 3^k + 1 for 3^k + 1 <= n <= 2*3^k, %C A308432 a(n) = 3^(k+1) + 1 - n for 2*3^k + 1 <= n <= 3^(k+1), %C A308432 and thus a(3^(k+1)) = 1, so the formula holds for all k. (End) %F A308432 Let t = 3^floor(log_3(n)); then %F A308432 a(n) = 1 if n = t, %F A308432 t + 1 if n <= 2*t and n != t, %F A308432 3*t - n + 1 otherwise. %o A308432 (C) %o A308432 //pow3 is a vector where pow3[n] = 3^n %o A308432 int f(int n){ %o A308432 int x = 0; %o A308432 while(pow3[x+1] <= n) x++; %o A308432 return x; %o A308432 } %o A308432 int a(int n){ %o A308432 int fn = f(n); %o A308432 if(n == pow3[fn]){ %o A308432 return 1; %o A308432 }else if(n<=(pow3[fn]<<1) && n!=pow3[fn]){ %o A308432 return pow3[fn]+1; %o A308432 }else{ %o A308432 return pow3[fn+1] - (n-1); %o A308432 } %o A308432 } %K A308432 nonn %O A308432 1,2 %A A308432 _Wilmer Emiro Castrillon Calderon_, Jun 06 2019