Can you change the Add 1 game to include the number 9? Yes you can!
Original video (part 1) · Original tutorial
The game initially calculates whether a given input is OK by subtracting the input from the given numbers, and if the result is 1111, the input is correct. This is based on the idea that the difference between two sequences 0000-8888 is 1111 if you added 1 to each of the given numbers. This rules out the number 9 from the game, though!
Adding number 9 back into the game is fairly simple:
- First, we need to determine that, given we're working with single digits, 9 plus one = 0. So, the user needs to input 0 to add one to a 9.
- Then, we'll iterate over the digits of the input and the given number, and check that the difference between them is 1. This will go wrong when comparing 9 and 0, so we'll write an exception for that.