|
|
A339091
|
|
a(1)=a(2)=1; thereafter if n is even, a(n) is the cumulative sum of the odd digits so far; and if n is odd, a(n) is the cumulative sum of the even digits so far.
|
|
4
|
|
|
1, 1, 0, 2, 2, 2, 6, 2, 14, 3, 18, 7, 26, 14, 38, 18, 54, 24, 64, 24, 80, 24, 94, 33, 98, 48, 118, 50, 126, 56, 140, 62, 152, 68, 168, 69, 188, 79, 204, 95, 210, 110, 212, 113, 216, 119, 224, 130, 232, 137, 236, 151, 244, 158, 262, 164, 282, 165, 300, 174, 304, 185, 316, 195, 322, 213, 328, 220, 342, 223
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,4
|
|
COMMENTS
|
The first term of the sequence, a(1), is called "the seed".
|
|
LINKS
|
|
|
EXAMPLE
|
As n=7 is odd, a(7) = sum of all even digits to the left of a(7) = 0 + 2 + 2 + 2 = 6;
as n=8 is even, a(8) = the sum of all odd digits to the left of a(8) = 1 + 1 = 2);
as n=9 is odd, a(9) = the sum of all even digits to the left of a(9) = 0 + 2 + 2 + 2 + 6 + 2 = 14; etc.
|
|
MATHEMATICA
|
Block[{a = {1}, s}, Array[Set[s[#], 0] &, 9]; Do[(MapIndexed[AddTo[s[First[#2]], #1] &, #]; AppendTo[a, Total@ Map[# s[#] &, If[EvenQ@ i, {2, 4, 6, 8}, {1, 3, 5, 7, 9}]]]) &@ Most@ DigitCount@ Last@ a, {i, 69}]; a ] (* Michael De Vlieger, Dec 10 2020 *)
|
|
PROG
|
(PARI) sumo(d) = sum(k=1, #d, if (d[k] % 2, d[k]));
sume(d) = sum(k=1, #d, if (!(d[k] % 2), d[k]));
esum(va, k) = sum(i=1, k, sumo(digits(va[i])));
osum(va, k) = sum(i=1, k, sume(digits(va[i])));
lista(nn) = {my(va = vector(nn)); va[1] = 1; va[2] = 1; for (n=3, nn, va[n] = if (n % 2, osum(va, n-1), esum(va, n-1)); ); va; } \\ Michel Marcus, Dec 10 2020
(Python)
def aupto(nn):
seed, s = 1, [0, 0]
alst = [None, seed]
for n in range(2, nn+1):
s[0] += sum(int(d) for d in str(alst[-1]) if d in "02468")
s[1] += sum(int(d) for d in str(alst[-1]) if d in "13579")
alst.append(s[not n%2])
return alst[1:] # use alst[n] for a(n)
|
|
CROSSREFS
|
|
|
KEYWORD
|
base,nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|