login
A006940
Rows of Pascal's triangle mod 3.
(Formerly M4806)
3
1, 11, 121, 1001, 11011, 121121, 1002001, 11022011, 121212121, 1000000001, 11000000011, 121000000121, 1001000001001, 11011000011011, 121121000121121, 1002001001002001, 11022011011022011, 121212121121212121, 1000000002000000001, 11000000022000000011, 121000000212000000121
OFFSET
0,2
COMMENTS
Subsequence of A118594. - Chai Wah Wu, Jul 30 2025
REFERENCES
C. Pickover, Mazes for the Mind, St. Martin's Press, NY, 1992, p. 353.
N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
MATHEMATICA
a[n_] := FromDigits[Table[Mod[Binomial[n, k], 3], {k, 0, n}]]; Array[a, 25, 0] (* Amiram Eldar, Nov 22 2018 *)
PROG
(PARI) a(n)=fromdigits(apply(x->x%3, binomial(n))); \\ Michel Marcus, Nov 21 2018
(Python)
from math import prod, comb
from gmpy2 import digits
def A006940(n):
if n==0: return 1
c, l = '', len(s:=digits(n, 3))
for k in range(m:=n+2>>1):
t = digits(k, 3).zfill(l)
c += str(prod(comb(int(s[i]), int(t[i]))%3 for i in range(l))%3)
return int(c+c[m-2+(n&1)::-1]) # Chai Wah Wu, Jul 30 2025
CROSSREFS
KEYWORD
nonn
EXTENSIONS
More terms from Michel Marcus, Nov 21 2018
STATUS
approved