OFFSET
1,4
COMMENTS
This sequence is related to the Josephus Problem, which can be modeled with the Australian Under Down Shuffle, one card placed under the deck, one card laid down on the table until all the cards are on the table.
LINKS
FORMULA
a(1) = 1, a(2) = 1, a(n) = (a(n-2) + 3) (mod n) if (a(n-2) + 3) (mod n) is not 0; a(n) = n if (a(n-2) + 3) (mod n)=0.
Any number n can be written as either 2*(3^k) + 2m (where 0 <= m < 3^k, k = 0,1,2,...) or 3^k + 2m (where 0 <= m < 3^k, k = 0,1,2,...), in either case a(n) = 3m + 1.
MATHEMATICA
nxt[{n_, a_, b_}]:={n+1, b, If[Mod[a+3, n+1]!=0, Mod[a+3, n+1], n+1]}; NestList[nxt, {2, 1, 1}, 70][[;; , 2]] (* Harvey P. Dale, Jul 27 2024 *)
PROG
(PARI) a(n) = if (n <= 2, 1, my(x = (a(n-2) + 3) % n); if (x, x, n)); \\ Michel Marcus, Aug 20 2020
CROSSREFS
KEYWORD
nonn
AUTHOR
Robert W. Vallin, Aug 18 2020
EXTENSIONS
More terms from Michel Marcus, Aug 20 2020
STATUS
approved