cp's OEIS Frontend

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.

Showing 1-1 of 1 results.

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.

Original entry on oeis.org

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
Offset: 1

Views

Author

Alex Ratushnyak, Nov 27 2014

Keywords

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.

Examples

			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, ...
		

Crossrefs

Cf. A252448 (inverse), A252458 (fixed points).

Programs

  • 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
  • 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:]
    
Showing 1-1 of 1 results.