Created
January 20, 2012 10:02
-
-
Save aeberspaecher/1646516 to your computer and use it in GitHub Desktop.
Hailstone sequence in Cython
This file contains hidden or 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
"""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