Sally likes to play a math game with herself. She starts with a number, x. She then will repeatedly do a move to x. A move consists of either multiplying the number by 3 or subtracting 1. For example, if x=2, she could multiply by 3 to get 6, subtract 1 to get 5, and multiply by 3 again to get 15, for a total of 3 moves to get from 2 to 15. What is the minimum number of moves she could use to get from 1 to 100?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
It is easier to reverse the rules and look for a path from 1 0 0 to 1 . When going backward a simple heuristic suffices:
Our two possible moves are n → n / 3 and n → n + 1
From the number n
a) if 3 ∣ n , move to n / 3
b) if 3 ∤ n , move to n + 1 .
Clearly if 3 ∤ n we cannot move to n / 3 as every number in the forward path is an integer.. So to show the soundness of this approach, it suffices to show that, when possible, it's preferable to divide by 3 than to add 1 .
This is fairly obvious: the path of
n → n / 3 → n / 3 + 1
gets us to the same place as
n → n + 1 → n + 2 → n + 3 → n / 3 + 1 ,
and it takes 2 fewer steps.
So, our backwards path goes 1 0 0 → 1 0 1 → 1 0 2 → 3 4 → 3 5 → 3 6 → 1 2 → 4 → 5 → 6 → 2 → 3 → 1
Our optimal path has 12 steps.