Steve "Woz" Wozniak — co-founder of Apple Computers — collected telephone numbers, amongst other things. His big dream was to get hold of a telephone number in which only one digit was repeated. However, for the largest part of his life, Silicon Valley did not have any zone codes of three equal digits. Therefore, Woz had to be satisfied with numbers like 221-111-1111.
When he was eavesdropping on the mobile telephone traffic, he noticed that a new zone code had been taken into use: 888. After months of administrative fuss and waiting he finally got hold of his number: 888-888-8888. It was his new mobile phone number and with that his most valuable collector's item.
The number soon appeared to be useless. He received more than a hundred mistaken calls a day. At first, this amount of wrong connections seemed pretty inexplicable, given the fact that it was almost impossible to dial the number incorrectly. What was even more unusual was that no one could ever be heard on the other side of the connection. Just silence. Well, actually is was silence under various forms: death silence, sometimes the sound of a television in the background, or someone that was talking very quietly in English or in Spanish, or sometimes weird gargling sounds. Woz often kept listening, intrigued.
But one day, while he had his phone pressed to his ear, Woz clearly heard a woman's voice at a certain distance saying "Hey! What are you doing with that?". The receiver on the other side was torn away and the connection was broken. This was the solving piece of the puzzle. The hundreds of calls, the dead silence, the gargling sounds: babies. They had picked up the receiver and started pushing buttons on the bottom of the machine. And that made the same sound over and over: 'Beep beep beep beep beep beep beep beep beep beep." The American children had played their first prank, subconsciously. And the person who answered their calls was Woz.
This story contains a sense of justice being served, as Woz started his career as a prank caller and hacker of telephone systems.
To determine the chance that a baby coincidentally presses a certain telephone number, we have developed a score system for telephone numbers. The higher the score, the smaller the chance that that particular number will be called by accident. To calculate the score, we use the keyboard below. Here we have the rows and columns of the grid that is formed by the digits. The key 8, for example, is on row 2 and in column 1.
Asked:
Write a function position to which a number $$n \in \mathbb{N}$$ must be given, to which applies that $$0 \leq n < 10$$. This number represents a key on the keyboard of a mobile phone. The function should print two integers, that respectively represent the number of the row and the number of the column of the key. Try to minimize the number of conditions that need to be tested to implement this function.
Use the function position to write a function movement to which two numbers $$n, m \in \mathbb{N}$$ must be given, to which applies that $$0 \leq n, m < 10$$. These numbers represent two keys of the keyboard of a mobile phone. The function should print an integer that indicates how many positions at the least you should move your finger horizontally and vertically in order to move from one key to another. We assume you never move your finger diagonally. Every movement to another row or column is seen as a single movement. For example, to move from key 8 to key 1, you have to make one horizontal and two vertical moves. This is a total of three moves.
Use the function movement to write a function fingermovement. To this function, the string representation of a phone number should be given. The string may consist of a random sequence of characters, but only the digits of the string form the actual phone number. The function should print an integer, that represents the total amount of movements your fingers should do in order to dial the phone number.
>>> position(8)
(2, 1)
>>> position(0)
(3, 1)
>>> movement(8, 8)
0
>>> movement(8, 9)
1
>>> movement(8, 1)
3
>>> fingermovement('888-888-8888')
0
>>> fingermovement('053/67.83.47')
16