Skip to content

Instantly share code, notes, and snippets.

@aeberspaecher
Created January 20, 2012 10:02
Show Gist options
  • Save aeberspaecher/1646516 to your computer and use it in GitHub Desktop.
Save aeberspaecher/1646516 to your computer and use it in GitHub Desktop.
Hailstone sequence in Cython
"""Hailstone sequence.
"""
# compile with
# cython hailstoneCython.pyx
# -O2 -shared -fPIC -march=native -IPATH_TO_PYTHON.H -o hailstoneCython.so hailstoneCython.c
cpdef list hailstone(int n):
cdef list seq
seq = [n]
while n>1:
n = 3*n + 1 if n & 1 else n//2
seq.append(n)
return seq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment