Broken Ways (Logic problem)
This problem was published on Newton School website, “Question of the day 9/jan/2023”.
Problem statement:
Newton wants to reach the top of a staircase that has some broken steps (he cannot visit those steps). He can climb 1 or 2 steps at a time.
Example of a staircase of 15 steps with the steps 3 and 9 broken. The valid steps to visit are: 1,2, 4,5,6,7,8, 10,11,12,13,14,15.
One possible way to reach the top on this staircase is visiting the steps: 2,4,5,7,8,10,12,14,15 (sometimes Newton climbed 1 step and others he climbed 2 steps).
The object of the problem is to find the number of different ways that Newton can reach the top of the staircase.
Get Rogerio Penchel’s stories in your inbox
Join Medium for free to get updates from this writer.
Here I show one solution:
This problem remembers the “Fibonacci Sequence”. But why? Because since you can only reach a step from step-1 or step-2, the number of ways you can reach a step is the sum of “ways you can reach the step-1” + “ways you can reach the step-2”.
So, to reach step 1, you have only 1 way (climb from ground to step 1); to reach step 2 you have 2 ways (climb from ground directly to step 2 or climb from step 1), to reach step 3 you have 3 ways (1 way from step 1 + 2 ways from step 2), to reach step 4 you have 5 ways (2 ways from step 2 + 3 ways from step 3), to reach step 5 you have 8 ways (3 ways from step 3 + 5 ways from step 4) and so on until the last step.
But this is exactly the Fibonacci Sequence! Yes, but this problem has a twist, “broken steps” have been added. Okay, no problem, since Newton can’t visit the broken steps, just set 0 ways to reach them.
Coming back to our example, with steps 3 and 9 broken, we have this “Fibonacci Broken Sequence”: 1, 2, 0, 2, 2, 4, 6, 10, 0, 10, 10, 20, 30, 50, 80.
So, at this staircase, Newton has 80 different ways to climb it up.
Now, you can implement the Fibonacci Broken Sequence Algorithm in your favorite programming language and upload it to the Newton School website, which has lots of cool problems to be solved in the Question of the Day session.
If you found this article useful, please follow me to get new articles about math, logic and programming. I really appreciate it.
Have a good time!








