Challenge - Keypad puzzle
|
02-14-2020, 12:17 PM
(This post was last modified: 02-14-2020 01:43 PM by pinkman.)
Post: #14
|
|||
|
|||
RE: Challenge - Keypad puzzle
I still haven't finished a clean implementation in HPPL, but I think I found an elegant solution in python.
Elegant but brut force (find all numbers and divide them by 11) as I requested. A few preliminary comments about the methods: What I call a 'move' is the path followed by your finger on the keypad between 2 keys. Suppose you start from the '5' key (coordinates 2x2 on the grid) : you have 8 possible moves : 4 (left, right, up, down) x 2 (clockwise and counter-clockwise). Starting from other keys reduces the number of authorized moves, but the principle is the same. A move from '5' key is -1 ('4' key), +1 ('6' key), -3 ('2' key) or +3 ('8' key). To find the number formed by the square, you make 3 moves after having used the initial key, which makes 4 digits. After a horizontal move (+/-1) you have to make a vertical move (+/-3), and then an horizontal move in the opposite direction of the previous horizontal one, then a vertical move in the opposite direction of the previous vertical one. Mathematically there are two properties to follow a consecutive square on the keypad : 1- If we call m our first move (being -1, +1, -3 or +3), then the third move is -m. 2- If we call m' our second move (being -1, +1, -3, +3), then you'll have ton constraint |m|≠|m'| (in readable language: +/-1 is followed by +/-3, +/-3 is followed by +/-1). For each key, the moves are m, m', -m. PHP Code: result = [] And the result : Code:
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)