Created
May 3, 2009 11:37
-
-
Save bemasher/105958 to your computer and use it in GitHub Desktop.
This file contains 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
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