Skip to content

Instantly share code, notes, and snippets.

@de1o
Created May 16, 2012 12:31
Show Gist options
  • Save de1o/2709989 to your computer and use it in GitHub Desktop.
Save de1o/2709989 to your computer and use it in GitHub Desktop.
colaz
from xlwt import Workbook
def colaz(n, cnt, row):
if n == 1:
print cnt
row.write(1, str(cnt))
return 0
if n%2 == 0:
n = n/2
else:
n = 3*n+1
colaz(n, cnt + 1, row)
wb = Workbook()
sheet = wb.add_sheet('Sheet1')
for i in range(65535):
row = sheet.row(i)
row.write(0, str(i+1))
colaz(i+1, 0, row)
wb.save('colaz.xls')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment