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 = []
movr = [[3], [-3,3], [-3]] # authorized moves on each row from bottom to top (first to third)
movc = [[1], [-1,1], [-1]] # authorized moves on each column (left to right)
a = 0
for i in movr: # step accross each row...
for j in movc: # and accross each column
a += 1 # name (number) of the key
for k in i: # start moving along the row
for l in j: # and along the column
result.append(a*1000 + (a + k)*100 + (a + k + l)*10 + (a + k + l - k))
for k in j: # then start moving along the column
for l in i: # and along the row
result.append(a*1000 + (a + k)*100 + (a + k + l)*10 + (a + k + l - k))
for i in result:
print(i, " modulo (11) -> ", i %11)
And the result :
Code:
1452 modulo (11) -> 0
1254 modulo (11) -> 0
2541 modulo (11) -> 0
2563 modulo (11) -> 0
2145 modulo (11) -> 0
2365 modulo (11) -> 0
3652 modulo (11) -> 0
3256 modulo (11) -> 0
4125 modulo (11) -> 0
4785 modulo (11) -> 0
4521 modulo (11) -> 0
4587 modulo (11) -> 0
5214 modulo (11) -> 0
5236 modulo (11) -> 0
5874 modulo (11) -> 0
5896 modulo (11) -> 0
5412 modulo (11) -> 0
5478 modulo (11) -> 0
5632 modulo (11) -> 0
5698 modulo (11) -> 0
6325 modulo (11) -> 0
6985 modulo (11) -> 0
6523 modulo (11) -> 0
6589 modulo (11) -> 0
7458 modulo (11) -> 0
7854 modulo (11) -> 0
8547 modulo (11) -> 0
8569 modulo (11) -> 0
8745 modulo (11) -> 0
8965 modulo (11) -> 0
9658 modulo (11) -> 0
9856 modulo (11) -> 0