```
def three_x(seed):
e = lambda x: not (x % 2)
n = int(seed)
t = [n]
s = 0
while n > 1:
n = n // 2 if e(n) else 3 * n + 1
t.append(n)
s += 1
return s, t
```

```
for x in range(1, 10):
print (three_x(x))
(0, [1])
(1, [2, 1])
(7, [3, 10, 5, 16, 8, 4, 2, 1])
(2, [4, 2, 1])
(5, [5, 16, 8, 4, 2, 1])
(8, [6, 3, 10, 5, 16, 8, 4, 2, 1])
(16, [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1])
(3, [8, 4, 2, 1])
(19, [9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1])
```

```
>>> print (three_x(1 << 10))
(10, [1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1])
>>>
```

Hi,

I think the bigger q is, have you found an endless sequence yet ?

Took me a few minutes to clock it, but I knew the 3n + 1 felt familiar.

I think thatâ€™s the **Collatz conjecture**:

if even, divide by 2

if odd, multiply by 3 and add 1

stop when reach 1

The conjecture says the sequence is finite.

â€¦ I donâ€™t know if this has been proved [or disproved] yet.

Well done, both.

No, and doubtless wonâ€™t in my lifetime, even with a super computer, not by brute force, at least.

Given the infinite supply of integers, one suspects it will be easier to disprove, should that ever happen. Wouldnâ€™t want to be the Doctoral Supervisor on that PhD. The poor candidate might have gray hair and still not be any nearer.

Fun little algorithm, for what itâ€™s worth.