A100707 a(1) = 1; for n > 1, a(n+1)=a(n)-k if there exists a positive number k (take the smallest) that has not yet been used and is such that a(n+1) is new and >0, otherwise a(n+1) = a(n)+k if the same conditions are satisfied.
1, 2, 4, 7, 3, 8, 14, 6, 13, 22, 12, 23, 11, 24, 10, 25, 9, 26, 5, 27, 45, 21, 40, 20, 43, 18, 44, 17, 46, 16, 47, 19, 51, 15, 48, 82, 42, 77, 39, 76, 37, 78, 36, 79, 35, 80, 34, 81, 33, 83, 32, 84, 31, 85, 30, 86, 29, 87, 38, 97, 28, 88, 149, 75, 137, 74
Offset: 1
Examples
1 -> 1+1 = 2 and k=1 has been used as a difference. 2 -> 2+4 = 4 and k=2 has been used as a difference. 4 could go to 4-3 = 1, except that 1 has already appeared in the sequence; so 4 -> 4+3 = 7 and k=3 has been used as a difference. 7 -> 7-4 = 3 (for the first time we can subtract) and k=4 has been used as a difference. And so on.
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
Crossrefs
Programs
-
Haskell
import Data.List (delete) import qualified Data.Set as Set (insert) import Data.Set (singleton, member) a100707 n = a100707_list !! (n-1) a100707_list = 1 : f 1 (singleton 1) [1..] where f y st ds = g ds where g (k:ks) | v <= 0 = h ds | member v st = g ks | otherwise = v : f v (Set.insert v st) (delete k ds) where v = y - k h (k:ks) | member w st = h ks | otherwise = w : f w (Set.insert w st) (delete k ds) where w = y + k -- Reinhard Zumkeller, Jul 19 2013
Extensions
Data corrected for n > 46 by Reinhard Zumkeller, Jul 19 2013
Comments