A329068 a(1) = 1; thereafter if the sum of digits of all previous terms up to a(n) is even then a(n+1) = (sum of digits of all previous terms)/2, otherwise a(n+1) = (sum of digits of all previous terms)*3 + 1.
1, 4, 16, 6, 9, 82, 112, 124, 24, 27, 190, 220, 232, 42, 45, 298, 59, 66, 72, 460, 490, 88, 96, 622, 652, 115, 712, 742, 130, 132, 135, 838, 149, 156, 162, 1000, 167, 174, 180, 1108, 1138, 196, 204, 207, 1270, 1300, 1312, 222, 225, 1378, 239, 246, 252, 1540, 1570, 268, 276
Offset: 1
Links
- Bence BernĂ¡th, Table of n, a(n) for n = 1..100001
Programs
-
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