I like puzzles that are easy to state and don’t require a lengthy explanation. Today’s puzzle falls into that category.
It comes from one of my oldest and best friends, who asked me this simple but perplexing question: What is the smallest number evenly divisible by 225 that contains only the digits 1 and 0?
If you struggle to find the answer analytically, and you know how to code, see if you can solve it algorithmically, using a computer program. It’s a fun programming problem.
Click here to reveal the solution.
I know of three ways to solve this problem:
The Slow Search Method
This approach starts with 225 and multiplies it by an ever-increasing sequence of multiples looking for a number that contains only ones and zeros. Here’s the Python code to implement this method:
Which prints the following result:
After 49382716 iterations and 116 seconds, found 11111111100.
The Fast Search Method
This strategy observes that the desired result looks like a binary number (albeit in base 10) so it tests a sequence of binary numbers, treating each as a base 10 number, looking for one that’s evenly divisible by 225. This is much faster than the previous method because it automatically skips all the base 10 numbers that have digits other than 1 and 0. Here’s the Python code:
which prints the following result:
After 2037 iterations and 0.016 seconds, found 11111111100.
The Analytical Method
Because 225 ends in 25, multiples of 225 will end in one of four possible digit pairs: 25, 50, 75 or 00. The only one that meets our requirements (only 1s and 0s allowed) is the last one so we know that the result must end with two 0s.
We can also see that 225 is divisible by 9 (you can check any number for divisibility by 9 by seeing if the digits sum to 9). Therefore, any multiple of 225 must also be divisible by 9. So we know the digits in the result must end in 00, contain only 1s and 0s, and sum to 9.
With those constraints, the smallest possible number meeting our requirements will contain nine consecutive 1s and will end with two 0s: 11111111100.