Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
Created June 28, 2011 22:23
Show Gist options
  • Save b1naryth1ef/1052395 to your computer and use it in GitHub Desktop.
Save b1naryth1ef/1052395 to your computer and use it in GitHub Desktop.
Homework Week of June 27th
#Imports
import math
import csv
x = range(1,500)
#Fib (Using square roots to preserve ram)
def fib(n):
fiby = ((1+math.sqrt(5))**n-(1-math.sqrt(5))**n)/(2**n*math.sqrt(5))
return int(fiby)^2
#Mod or % Function Rewritten:
def modi(a,n):
ai = int(a)
ni = int(n)
return ai - (ai//ni) * ni
#Write results of Fib() to CSV, with ID Numbers.
def write(file,list):
z = 0
f = csv.writer(open(file, 'wb'), delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
for item in list:
z+=1
row = (z,item)
f.writerow(row)
list = map(fib,x) #Generates list of Fib numbers
write("test.csv",list) #Writes list of Fib numbers to CSV (With ID Numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment