%I #25 Nov 19 2023 13:02:35
%S 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,
%T 30,48,31,38,21,28,27,34,33,52,35,42,29,36,39,40,49,50,58,51,54,41,44,
%U 37,60,43,66,53,84,67,68,61,62,45,46,55,56,59,76,94,77,90
%N 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.
%C A permutation of natural numbers generated by the following algorithm.
%C 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.
%H Reinhard Zumkeller, <a href="/A249990/b249990.txt">Table of n, a(n) for n = 1..10000</a>
%H Popular Computing (Calabasas, CA), <a href="/A249990/a249990.png">Problems 195 and 196</a>, Vol. 5 (No. 55, 1977), annotated and scanned copy of page PC55-4. See Problem 195.
%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>
%e Start with:
%e 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ...
%e After the first step:
%e 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 18, ...
%e After the 2nd step:
%e 2, 1, 6, 3, 4, 7, 8, 5, 12, 9, 10, 13, 14, 11, 18, 15, 16, ...
%e After the 3rd step:
%e 2, 1, 6, 3, 4, 12, 5, 8, 7, 14, 13, 10, 9, 16, 15, 18, 11, ...
%o (Python)
%o TOP = 100
%o a = list(range(TOP))
%o for step in range(2,TOP):
%o numBlocks = (len(a)-1) // step
%o if numBlocks==0: break
%o a = a[:(1+numBlocks*step)]
%o for pos in range(1,len(a),step):
%o a[pos:pos+step] = a[pos+step-1:pos-1:-1]
%o for i in range(1, step+1): print(str(a[i]), end=',')
%o a[1:] = a[step+1:]
%o (Haskell)
%o a249990 n = a249990_list !! (n-1)
%o a249990_list = f 2 [1..] where
%o f k xs = reverse ys ++ f (k + 1) (g zs) where
%o g us = reverse vs ++ g ws where
%o (vs, ws) = splitAt k us
%o (ys, zs) = splitAt k xs
%o -- _Reinhard Zumkeller_, Dec 17 2014
%Y Cf. A000960, A026239, A249991.
%Y Cf. A252448 (inverse), A252458 (fixed points).
%K nonn
%O 1,1
%A _Alex Ratushnyak_, Nov 27 2014