Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created May 3, 2009 11:37
Show Gist options
  • Save bemasher/105958 to your computer and use it in GitHub Desktop.
Save bemasher/105958 to your computer and use it in GitHub Desktop.
import math
def PhiFrac(i): # 25 iterations will produce 10 digits of precision
if (i >= 0):
return 1.0 + (1.0 / phi_frac(i - 1))
return 1.0
def PhiSqrt(i): # 25 iterations will produce 10 digits of precision
if (i >= 0):
return math.sqrt(1.0 + phi_sqrt(i - 1))
return 1.0
def Fib(x):
if x == 0:
return 0.0
elif x == 1:
return 1.0
return fib(x - 1) + fib(x - 2)
def PhiFib(x): # Slowest approximation but the fib function is mostly to blame...
return fib(x+1.0)/fib(x)
def GetPrimes(p, i=1):
if i**2 < p[-1]:
p[i:] = filter(lambda x: x % p[i-1] != 0, p[i:])
return GetPrimes(p, i + 1)
return p
print GetPrimes(range(2,100))
def Factorial(value):
if value <= 1:
return 1
return value * Factorial(value - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment