Programming and Webmasters forum
HomeSearchRecent PostsLoginRegister Contact Us

Username  
Password
Announcing 14th Weekly Contest - From 25 July To 01 August.

Win every week on this forum.

Chek out How To Win?
 

Pages: [1]   Go Down
 
  Email this topic  |  Print
0 Members and 1 Guest are viewing this topic.

program for fibonnaci number in python

 
webmaster forum
raj  Offline
Contest Points: 100
 
New Coder
Posts: 25
Topics: 14
January 25, 2009, 02:24:38 AM

I was trying to write a program for Fibonacci as is described on wikipedia and the problem that I am facing is that no matter how big I keep the limit it says to be overflowing.
I have tried keeping it unlimited but still the same problem arises.
 
webmaster forum
polas  Offline
*
 
Hacker
Gender: Male
Posts: 1224
Topics: 78
WWW
January 25, 2009, 01:23:29 PM

Post the python code here, I don't know python but might be able to figure out what has gone wrong

Mesham Type Oriented Parallel Programming Language
Skydive in North East England
 
webmaster forum
singam  Offline
Contest Points: 100
 
New Coder
Posts: 39
Topics: 15
July 02, 2010, 08:31:08 PM

Although the recursive implementation given above is elegant and close to the mathematical definition, it is not very practical. Calculating the nth fibonacci number requires calculating two smaller fibonacci numbers, which in turn require two additional recursive calls each, and so on until all branches reach 1. The iterative solution is faster, but still repeats a lot of calculations when computing successive fibonacci numbers. To remedy this, we can employ memoization to cache previous computations.

We first establish a memoization "cache", which stores previously computed fibonacci numbers. In this case we use an ArrayList, initialized with the first two fibonacci numbers, as the cache. Note that we have also moved from using ints to using Java's BigInteger class, which provides arbitrary-precision integers. As a result, the memoized implementation can also compute much larger fibonacci numbers than the previous solutions (although they too could have been implemented using BigIntegers.
===============
Ben 10 Games


 
webmaster forum
Admin  Offline
*
 
Hacker
Location: India
Gender: Male
Posts: 1101
Topics: 94
Technical_Talk
WWW
July 03, 2010, 07:08:02 AM

@singam: Thank you for the post.

Watch out for the latest Weekly Contests | Contest Rules
A Game - Say "Hello"
We are looking for Global Moderator
 
  Email this topic  |  Print
Pages: [1]   Go Up
 
Jump to:  



Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC


Google visited last this page July 19, 2010, 02:31:51 PM

Valid XHTML 1.0 Transitional     Valid XHTML 1.0 Transitional