OFFSET
1,2
LINKS
Bence Bernáth, Table of n, a(n) for n = 1..100001
PROG
(MATLAB)
clear all;
length_seq=10000;
sequence(1)=1;
seq_for_digits(1)=sequence(1);
for i1=1:1:length_seq
if 0==mod(sum(seq_for_digits), 2)
sequence(i1+1)=sum(seq_for_digits)/2;
else
sequence(i1+1)=sum(seq_for_digits)*3+1;
end
append=num2str(sequence(i1+1))-'0';
seq_for_digits=[seq_for_digits append];
end
result=transpose(sequence);
(PARI) lista(nn) = {va = vector(nn); va[1] = 1; sd = sumdigits(va[1]); for (n=2, nn, if (sd % 2, va[n] = 3*sd+1, va[n] = sd/2); sd += sumdigits(va[n]); ); va; } \\ Michel Marcus, Nov 04 2019
(Python)
from itertools import islice
def agen(): # generator of terms
sd, an = 0, 1
while True:
yield an
sd += sum(map(int, str(an)))
an = 3*sd+1 if sd&1 else sd//2
print(list(islice(agen(), 60))) # Michael S. Branicky, Nov 12 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Bence Bernáth, Nov 03 2019
STATUS
approved