A093347 A 3-fractal "castle" starting with 0.
0, 1, 0, 3, 2, 3, 0, 1, 0, 9, 8, 9, 6, 7, 6, 9, 8, 9, 0, 1, 0, 3, 2, 3, 0, 1, 0, 27, 26, 27, 24, 25, 24, 27, 26, 27, 18, 19, 18, 21, 20, 21, 18, 19, 18, 27, 26, 27, 24, 25, 24, 27, 26, 27, 0, 1, 0, 3, 2, 3, 0, 1, 0, 9, 8, 9, 6, 7, 6, 9, 8, 9, 0, 1, 0, 3, 2, 3, 0, 1, 0, 81, 80, 81, 78, 79, 78, 81
Offset: 1
Links
- Amiram Eldar, Table of n, a(n) for n = 1..10000
- Benoit Cloitre, Graph of a(n) for n=1 up to 9
- Benoit Cloitre, Graph of a(n) for n=1 up to 27
- Benoit Cloitre, Graph of a(n) for n=1 up to 81
- Benoit Cloitre, Graph of a(n) for n=1 up to 243
Programs
-
Mathematica
a[n_] := Sum[(-1)^(i+1) * 3^IntegerExponent[i, 3], {i, 1, n-1}]; Array[a, 100] (* Amiram Eldar, Jun 17 2022 *)
-
PARI
a(n)=if(n<2,0,3^floor(log(n-1)/log(3))-a(n-3^floor(log(n-1)/log(3))))
-
PARI
a(n) = my(s=-1); fromdigits([if(d==1,s=-s) |d<-digits(n-1,3)], 3); \\ Kevin Ryde, Jan 01 2024
Formula
a(1) = 0 then a(n) = w(n) - a(n-w(n)) where w(n) = 3^floor(log(n-1)/log(3)).
a(3^n) = 0, a(3^n+1) = 3^n, a(3^n+2) = 3^n-1, a(3^n+3) = 3^n, etc.
a(n) = Sum_{i=1..n-1} (-1)^(i-1)*3^valuation(i, 3).