OFFSET
1,1
COMMENTS
A permutation of natural numbers generated by the following algorithm.
Start with the natural numbers. Reverse the order of numbers in each pair. Skip one pair. In the remainder (that is, "4, 3, 6, 5, 8, 7, 10, 9, 12, 11,...") reverse the order in each triple. Skip one triple. In the remainder (it starts with "7, 8, 5, 12, 9, 10") reverse the order in each tetrad. Skip one tetrad. And so on.
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
Popular Computing (Calabasas, CA), Problems 195 and 196, Vol. 5 (No. 55, 1977), annotated and scanned copy of page PC55-4. See Problem 195.
EXAMPLE
Start with:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ...
After the first step:
2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, ...
After the 2nd step:
2, 1, 6, 3, 4, 7, 8, 5, 12, 9, 10, 13, 14, 11, 18, 15, 16, ...
After the 3rd step:
2, 1, 6, 3, 4, 12, 5, 8, 7, 14, 13, 10, 9, 16, 15, 18, 11, ...
PROG
(Python)
TOP = 100
a = list(range(TOP))
for step in range(2, TOP):
numBlocks = (len(a)-1) // step
if numBlocks==0: break
a = a[:(1+numBlocks*step)]
for pos in range(1, len(a), step):
a[pos:pos+step] = a[pos+step-1:pos-1:-1]
for i in range(1, step+1): print(str(a[i]), end=', ')
a[1:] = a[step+1:]
(Haskell)
a249990 n = a249990_list !! (n-1)
a249990_list = f 2 [1..] where
f k xs = reverse ys ++ f (k + 1) (g zs) where
g us = reverse vs ++ g ws where
(vs, ws) = splitAt k us
(ys, zs) = splitAt k xs
-- Reinhard Zumkeller, Dec 17 2014
CROSSREFS
KEYWORD
nonn
AUTHOR
Alex Ratushnyak, Nov 27 2014
STATUS
approved