Created
October 29, 2019 21:45
-
-
Save wmmnola/b3845469f6ea747c99dc50566f20e436 to your computer and use it in GitHub Desktop.
Implementation of the sequence which is the subject of the collatz conjecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def collatz(n): | |
c = n/2 if n % 2==0 else (3*n+1)/2 | |
return int(c) | |
def seq(n, func=collatz): | |
lst = [] | |
while(n != 1): | |
lst.append(n) | |
n = func(n) | |
return lst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment