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
KEYWORD
AUTHOR
Wagner Martins, Jul 17 2023
STATUS
approved