OFFSET
1,2
LINKS
MATHEMATICA
f[n_] := Block[{a = {1}, g, b = Range[2, n]}, g[1] = 1; g[x_] := g[x] = If[EvenQ@ x, g[x/2], g[(x - 1)/2] + g[(x + 1)/2]]; Do[{AppendTo[a, #[[1, 1]]], Set[b, Last@ #]} &@ If[# > Length@ b, Break[], TakeDrop[b, {#}]] &@ g@ k, {k, 2, n}]; a]; f@ 103 (* Michael De Vlieger, Dec 29 2015, Version 10.2, after N. J. A. Sloane at A002487 *)
PROG
(Scheme, with defineperm1-macro from Antti Karttunen's IntSeq-library)
(defineperm1 (A266413 n) (if (<= n 1) n (let loop ((i 1) (the-nth-one (+ -1 (A002487 n)))) (cond ((not-lte? (A266414 i) n) (if (zero? the-nth-one) i (loop (+ i 1) (- the-nth-one 1)))) (else (loop (+ i 1) the-nth-one))))))
(define (A266414 n) (A266413 (- n))) ;; This returns inverse values of A266413 from its hidden cache that defineperm1-macro has prepared. #f is returned for those n that have not yet been encountered.
;; We consider a > b (i.e. not less than b) also in case a is #f.
;; (Because of the stateful caching system used by defineperm1-macro):
(define (not-lte? a b) (cond ((not (number? a)) #t) (else (> a b))))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Dec 29 2015
STATUS
approved