There is a frog jumping on lily pads labeled with natural numbers. It’s on the 2015th lily pad and can either go one step forward or backwards, except if it at any time is on a lily pad divisible by 6 it has to go forward. How many 15-steps paths are possible? The problem is […]
Tag: recursion
A Strange Recursion
This is a really nice recursion I wanted to share. We have to find the general formula for the nth term of the succession. We have: Also: By subtracting the two expressions and simplifying we get: Now, since we can further simplify to get the final form: By solving the recursion’s equation we can find […]
Great Classic: Hanoi Tower
Tower of Hanoi consists of three pegs or towers with n disks placed one over the other. The objective of the puzzle is to move the stack to another peg following these simple rules. Only one disk can be moved at a time. No disk can be placed on top of the smaller disk. In […]
Python Sudoku Solver
Writing a sudoku solver is a great example to show how recursion works in Python. This particular technique is called ‘Backtracking’. Let’s see a possible implementation. How Sudoku Works There are 3 rules you have to follow when solving a sudoku: All the numbers in a row must be different; All the numbers in a […]