Coding Challenge: Caching

Test your caching in Python skills by solving the challenge in this lesson.

We'll cover the following

Problem

You have been given a fib() function that calculates the nth number in the Fibonacci sequence. The function works correctly with smaller numbers such as 4, 5, 10, etc. However, when we want to calculate the numbers much ahead in the series such as 100th100^{th}, it takes too long to finish computing.

The Fibonacci Sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…

Written as a rule, the expression is:

Xn=Xn1+Xn2X_n = X_{n-1} + X_{n-2}

Get hands-on with 1200+ tech skills courses.