login
A359803
a(1) = 1; for n > 1, a(n) = n-1 if a(n-1) = 1, otherwise, apply the '3x+1' function to a(n-1)
0
1, 1, 2, 1, 4, 2, 1, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, 24, 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1, 49, 148, 74, 37, 112, 56, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8
OFFSET
1,3
EXAMPLE
For n = 5, the sequence so far is (1, 1, 2, 1) a(4) = 1, therefore a(5) = 5-1 = 4.
For n = 6, the sequence so far is (1, 1, 2, 1, 4), 4 is not 1, so we apply the '3x+1' function, 4 is even, so we divide it by 2, therefore a(6) = 4/2 = 2.
For n = 9, the sequence so far is (1, 1, 2, 1, 4, 2, 1, 7), 7 is not 1, so we apply the '3x+1' function, 7 is odd, so we multiply it by 3 and add 1, therefore a(9) = 3*(7)+1 = 22.
PROG
(Python)
def a(length):
sequence = [1]
while len(sequence) < length:
last_term = sequence[-1]
if last_term == 1:
next_term = len(sequence)
elif last_term % 2 == 0:
next_term = last_term // 2
else:
next_term = 3 * last_term + 1
sequence.append(next_term)
return sequence
CROSSREFS
Selected rows from A070165.
Cf. A014682.
Sequence in context: A277812 A134586 A135287 * A290650 A346874 A348533
KEYWORD
nonn,look,easy
AUTHOR
Wagner Martins, Jul 17 2023
STATUS
approved