|
|
A249990
|
|
Start with the natural numbers, reverse the order in each pair, skip one pair, reverse the order in each triple, skip one triple, and so on.
|
|
5
|
|
|
2, 1, 6, 3, 4, 12, 5, 8, 7, 16, 9, 10, 13, 14, 22, 15, 18, 11, 24, 17, 32, 25, 26, 19, 20, 23, 30, 48, 31, 38, 21, 28, 27, 34, 33, 52, 35, 42, 29, 36, 39, 40, 49, 50, 58, 51, 54, 41, 44, 37, 60, 43, 66, 53, 84, 67, 68, 61, 62, 45, 46, 55, 56, 59, 76, 94, 77, 90
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
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
|
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
|
|
CROSSREFS
|
|
|
KEYWORD
|
nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|