Python is fast and can operate on big numbers.

With Django sub forum.
KBleivik
Site Admin
Posts: 178
Joined: Tue Sep 29, 2009 6:25 pm
Location: Moss Norway
Contact:

Python is fast and can operate on big numbers.

Postby KBleivik » Tue Feb 15, 2011 12:23 pm

The fibonacci numbers are well known. Computing the n first Fibonacci numbers are often used in many examples. Here

Code: Select all

# fibonacci generator code from diveintopython.org

def fibonacci(max):
    a, b = 0, 1
    while a < max:
        yield a
        a, b = b, a+b

for n in fibonacci(1000000000000000000000000000000000000000000000000000000):
    print (n),

Is an example of computing the first Fibonacci numbers up to one septendecillion: http://www.jimloy.com/math/billion.htm, more precisely:
1 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000

The formula is ultra fast, and there is no problem with the computation as long as there is enough memory. The formula was cut from the example on the well known code site: http://dpaste.com/ . I only modified the code for a bigger argument and to make it compatible with Python 3.*.

If you are new to programming, start here: http://wiki.python.org/moin/BeginnersGu ... rogrammers

Another Python book: http://diveintopython.org/ that is claimed to be a Python book for experienced programmers.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 1 guest