Snaking Number Challenge
I wonder how many snaking numbers there are between 1 and 50,000?
Snaking Numbers, in this game, are numbers which can be typed out on a traditional numberpad (format below) by moving one key up, down, left, or right.
7 8 9 4 5 6 1 2 3 0
For example, if you start with the number 5, you could select 4, 6, 8, or 2 as your next valid move - however 7, 3, 9, and 1 are off-limits as they are positioned diagonally to the current key. So, if you have 5, then 2, your next viable key choices are 0, 1, 3, or 5 again.
In this Code Golf exercise, you are to output a list of all the positive snaking numbers between 1 and 50k, along with a final count of all the numbers that meet the criterion.
- Numbers cannot start with a Zero.
- Numbers must be whole positive integers.
- Each consecutive number, read from left to right, must "snake" around the numberpad.
- The snake cannot travel diagonally across keys
- The number 0 can be accessed from both numbers 1 and 2
- Numbers cannot be paired (eg: 22)
Examples of valid Snaking Numbers:
12369 45201 1254 10102 1 12 987
Examples of invalid numbers
1238 - 8 is not connected 0001 - multiple leading 0s 0101 - leading 0 159 - snake cannot travel diagonally 4556 - duplicate 5
As per normal Code Golfs, the aim is fewest bytes!
According to my maths and rules, you should have 670 valid snaking numbers in your list, plus 670 itself printed as the last number.