Skip to content

Instantly share code, notes, and snippets.

@scottnguyen
Created July 31, 2012 02:21
Show Gist options
  • Save scottnguyen/3212868 to your computer and use it in GitHub Desktop.
Save scottnguyen/3212868 to your computer and use it in GitHub Desktop.
def fib(n):
a = 1
b = 1
"""
Don't try to define everything in one line.
K.I.S.S. for now.
"""
while a < n:
temp = a
a = b
b = temp+b
return a
"""
Keeping a dictionary or a list for previously computed Fibonacci values turns
out to be very useful. You can keep track of previously computed solutions in
memory for constant look up speeds, rather compute it linearly for each input
value. Try making it yourself!
"""
""" Good Python style says you should put your
main inside of a function and call it with
if __name__ == '__main__':
main()
"""
def main():
fz = open ("dragonig.txt", "a")
value = (fib(4000000))
fz.write(str(fib(4000000)))
fz.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment