Skip to content

Instantly share code, notes, and snippets.

@wmmnola
Created October 29, 2019 21:45
Show Gist options
  • Save wmmnola/b3845469f6ea747c99dc50566f20e436 to your computer and use it in GitHub Desktop.
Save wmmnola/b3845469f6ea747c99dc50566f20e436 to your computer and use it in GitHub Desktop.
Implementation of the sequence which is the subject of the collatz conjecture
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