|
|
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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,3
|
|
LINKS
|
|
|
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
|
|
|
STATUS
|
approved
|
|
|
|