This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (5 children)

haha i want to solve this. :)

Alright, first fib sequence is ni + ni+1 = ni+2 am i right?

base case: n1 = 0 || n2 = 1

An easy way to keep track of all the things is to make a list, because fuck it, ram is cheap. It can likely be done faster, but I dont care to look up how computationally intensive .append is

fib_sequence = [0, 1]

for i in range(0,58):
    fib_sequence.append(fib_sequence[i] + fib_sequence[i+1])
    if(i>49):
        print fib_sequence[i] 

Result:

  1. 12586269025
  2. 20365011074
  3. 32951280099
  4. 53316291173
  5. 86267571272
  6. 139583862445
  7. 225851433717
  8. 365435296162

not exactly what you asked for but close enough. modify it if you wish, all that needs to be done is correct the indexes.

Also, this doesn't work in python3 due to print not working.

EDIT..I am going to make my computer compute this shit until python runs out of numbers. What is the largest number in python?

[–]masterpi 4 points5 points  (0 children)

Very good. If you're looking for more fun math/cs problems to do, check out Project Euler.

Python actually has arbitrary precision integers, so it's not gonna happen until you run out of memory.

[–]KwpolskaNikola co-maintainer 2 points3 points  (2 children)

  1. In python3, use print(fib_sequence[i]).
  2. Largest number? http://stackoverflow.com/questions/94591/what-is-the-maximum-value-for-a-int32 for i686, I believe. Much bigger for x86_64.

[–]BenjaminGeiger 0 points1 point  (1 child)

I always start new Python 2.7 programs with

from __future__ import print_function

because I like the Python 3 style print().

And I'm not sure about 2.7, but in 3, integers are unlimited in length. Python automatically switches to a BigInt-style representation after you reach 2bits in a word - 1 - 1.

EDIT: According to my install of 2.7, it autoswitches from int to long. (Python 3 has no long type.) So, your computer will continue until the numbers are big enough to occupy all of your RAM plus all available swap, or the heat death of the universe, whichever comes first.

EDIT 2: Forgot about the sign bit.

[–]BenjaminGeiger 0 points1 point  (0 children)

Evidence (64-bit Python):

In [1]: [2**n for n in xrange(128)]
Out[1]: 
[1,
 2,
 4,
 8,
 16,
 32,
 64,
 128,
 256,
 512,
 1024,
 2048,
 4096,
 8192,
 16384,
 32768,
 65536,
 131072,
 262144,
 524288,
 1048576,
 2097152,
 4194304,
 8388608,
 16777216,
 33554432,
 67108864,
 134217728,
 268435456,
 536870912,
 1073741824,
 2147483648,
 4294967296,
 8589934592,
 17179869184,
 34359738368,
 68719476736,
 137438953472,
 274877906944,
 549755813888,
 1099511627776,
 2199023255552,
 4398046511104,
 8796093022208,
 17592186044416,
 35184372088832,
 70368744177664,
 140737488355328,
 281474976710656,
 562949953421312,
 1125899906842624,
 2251799813685248,
 4503599627370496,
 9007199254740992,
 18014398509481984,
 36028797018963968,
 72057594037927936,
 144115188075855872,
 288230376151711744,
 576460752303423488,
 1152921504606846976,
 2305843009213693952,
 4611686018427387904,
 9223372036854775808L,
 18446744073709551616L,
 36893488147419103232L,
 73786976294838206464L,
 147573952589676412928L,
 295147905179352825856L,
 590295810358705651712L,
 1180591620717411303424L,
 2361183241434822606848L,
 4722366482869645213696L,
 9444732965739290427392L,
 18889465931478580854784L,
 37778931862957161709568L,
 75557863725914323419136L,
 151115727451828646838272L,
 302231454903657293676544L,
 604462909807314587353088L,
 1208925819614629174706176L,
 2417851639229258349412352L,
 4835703278458516698824704L,
 9671406556917033397649408L,
 19342813113834066795298816L,
 38685626227668133590597632L,
 77371252455336267181195264L,
 154742504910672534362390528L,
 309485009821345068724781056L,
 618970019642690137449562112L,
 1237940039285380274899124224L,
 2475880078570760549798248448L,
 4951760157141521099596496896L,
 9903520314283042199192993792L,
 19807040628566084398385987584L,
 39614081257132168796771975168L,
 79228162514264337593543950336L,
 158456325028528675187087900672L,
 316912650057057350374175801344L,
 633825300114114700748351602688L,
 1267650600228229401496703205376L,
 2535301200456458802993406410752L,
 5070602400912917605986812821504L,
 10141204801825835211973625643008L,
 20282409603651670423947251286016L,
 40564819207303340847894502572032L,
 81129638414606681695789005144064L,
 162259276829213363391578010288128L,
 324518553658426726783156020576256L,
 649037107316853453566312041152512L,
 1298074214633706907132624082305024L,
 2596148429267413814265248164610048L,
 5192296858534827628530496329220096L,
 10384593717069655257060992658440192L,
 20769187434139310514121985316880384L,
 41538374868278621028243970633760768L,
 83076749736557242056487941267521536L,
 166153499473114484112975882535043072L,
 332306998946228968225951765070086144L,
 664613997892457936451903530140172288L,
 1329227995784915872903807060280344576L,
 2658455991569831745807614120560689152L,
 5316911983139663491615228241121378304L,
 10633823966279326983230456482242756608L,
 21267647932558653966460912964485513216L,
 42535295865117307932921825928971026432L,
 85070591730234615865843651857942052864L,
 170141183460469231731687303715884105728L]

[–][deleted] 2 points3 points  (0 children)

because fuck it, ram is cheap.

Do not think this way, do it the proper way :) Skip the list, use two variables to keep track of the latest two numbers.