OFFSET
1,2
COMMENTS
The sequence is a permutation of the positive integers.
LINKS
EXAMPLE
To obtain the 2nd term, take the first, 1. What is the smallest integer k so that k - the number of 1's in k's binary representation is 1? The answer, obviously, is 2. [A213723(1) = 2.]
There is no number that is 2 more than its binary weight [as A213723(2) = 0], therefore we just take 3 as the next term.
Following 3 we can choose either 4 or 5, but 4 is smaller, and is thus the next term of the sequence. [A213723(3) = 4.]
PROG
(Scheme) ;; With defineperm1-macro from Antti Karttunen's IntSeq-library.
(defineperm1 (A218252 n) (cond ((<= n 1) n) ((A213723 (A218252 (- n 1))) => (lambda (next_maybe) (if (not (zero? next_maybe)) next_maybe (let loop ((i (A000012 (- n 1)))) (if (not-lte? (A257683 i) n) i (loop (+ i 1)))))))))
;; We consider a > b (i.e. not less than b) also in case a is nil.
;; (Because of the stateful caching system used by defineperm1-macro):
(define (not-lte? a b) (cond ((not (number? a)) #t) (else (> a b))))
;; Antti Karttunen, May 04 2015
CROSSREFS
KEYWORD
nonn
AUTHOR
Nico Brown, Oct 24 2012
EXTENSIONS
Name slightly edited and links to A213723 in examples added by Antti Karttunen, May 04 2015
STATUS
approved
