Quantcast
Channel: Python - The Collatz Sequence - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by DeepSpace for Python - The Collatz Sequence

$
0
0

For sake of completeness, a recursive implementation for collatz (you already got enough good suggestions for inputting num):

def collatz(num):    print(num)    if num == 1:        return num    if num % 2 == 0:        return collatz(num // 2)    return collatz(3 * num + 1)collatz(3)

Outputs

3105168421

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>