OFFSET
1,3
COMMENTS
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..32768 (first 8193 terms from Antti Karttunen)
Eric Weisstein's World of Mathematics, Binomial Coefficient
EXAMPLE
In base 3 the terms look like 0, 1, 2, 10, 11, 20, 21, 100, 101, 102, 110, 111, 200, 201, 210, 211, 1000, 1001, 1002, 1010, 1011, 1020, 1021, 1100, 1101, 1102, 1110, 1111, 2000, 2001, 2010, 2011, 2100, 2101, 2 110, 2111, 10000
MAPLE
q:= n-> (l-> (h-> h=0 or h=1 and l[1+ListTools[Search](2, l)]
=0 )(numboccur(l, 2)))([convert(n, base, 3)[], 0]):
select(q, [$0..163])[]; # Alois P. Heinz, Jun 28 2021
PROG
(Perl) sub conv_x_base_n { my($x, $b) = @_; my ($r, $z) = (0, ''); do { $r = $x % $b; $x = ($x - $r)/$b; $z = "$r" . $z; } while(0 != $x); return($z); }
(Perl) for($i=1; $i <= 201; $i++) { if(("0" . conv_x_base_n($i, 3)) =~ /^(0|1)*(02)?(0|1)*$/) { print $i, ", "; } }
(Scheme, with Antti Karttunen's IntSeq-library)
(define (in_A051382? n) (let loop ((n n) (seen02yet? #f)) (cond ((zero? n) #t) ((= 1 n) #t) ((modulo n 3) => (lambda (r) (cond ((= r 2) (if (or seen02yet? (not (zero? (modulo (/ (- n r) 3) 3)))) #f (loop (/ (- n r) 3) #t))) (else (loop (/ (- n r) 3) seen02yet?))))))))
(Python)
import re
from sympy.ntheory.digits import digits
def b3(n): return "".join(map(str, digits(n, 3)[1:]))
def ok(n): return re.fullmatch('2(0|1)*|(0|1)*(02)?(0|1)*', b3(n)) != None
print(list(filter(ok, range(164)))) # Michael S. Branicky, Jun 26 2021
(PARI) is(n)=my(v=digits(n, 3)); for(i=1, #v, if(v[i]==2, if(i>1 && v[i-1], return(0)); for(j=i+1, #v, if(v[j]==2, return(0))); return(1))); 1 \\ Charles R Greathouse IV, Feb 23 2024
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
David W. Wilson, Antti Karttunen, Oct 24 1999
EXTENSIONS
a(0) = 0 prepended as a border-line case by Antti Karttunen, Nov 14 2014
Offset changed to 1 by Georg Fischer, Jun 28 2021
STATUS
approved