The alphabet contains 26 letters, whereas the keyboards of mobile phones and GPS instruments usually have fewer keys. In order to enter text on such keyboards, a technique called MultiTap has long been in use. The principle of this technique is simple: each letter of the alphabet is printed under each key (beginning on 2) in a three- or four-letter sequences as follows: (2=ABC, 3=DEF, 4=GHI, 5=JKL, 6=MNO, 7=PQRS, 8=TUV, 9=WXYZ). The system is used by repeatedly pressing the same key to cycle through the letters for that key.

Multitap keyboard

For example, pressing the 2 key once would indicate the letter A. In order to get the letter B, the 2 key must be pressed twice. Pausing for a set period of time will automatically choose the current letter in the cycle, as will pressing a different key. We will use a space (␣) to represent such a pause. This way, the sequence 2␣2 will result in AA, while the sequence 22 will result in B.

Opgave

Each line of the text file multitap.txt1 contains the multitap sequence that generates a single word that only exists of letters of the alphabet, followed by a space and the word itself. As the multitap sequence may itself contain spaces, it may thus happen that lines contain multiple spaces. You are asked to:

  1. Compose regular expressions that match with the sets described below. In these descriptions, $$\mathcal{M}$$ represents the set of all multitap sequences generating words that only contain letters of the alphabet. If $$m$$ represents the multitap sequence for a word, then $$m'$$ represents the multitap sequence from which spaces have been removed. Try to keep your regular expressions as short as possible.

    • $$\alpha = \{ m \in \mathcal{M}\,|\,$$ two positions before and after each space in $$m$$ there are two different digits that add up to 8; if $$m$$ has multiple spaces, consecutive space are separated by at least 4 digits $$\}$$

      examples: 222 266222 266 $$\in \alpha$$
        6444 44555 5777, 6444 44444 4477, 6444 444 4477 $$\not\in \alpha$$
    • $$\beta = \{ m \in \mathcal{M}\,|\,$$ consecutive digits of $$m'$$ form an increasing series $$\}$$

      examples: 22335566 66678 $$\in \beta$$
        444663 33997777 7 777666 664 $$\not\in \beta$$
    • $$\gamma = \{ m \in \mathcal{M}\,|\,$$ $$m'$$ contains at least 2 series of at least 4 consecutive equal digits $$\}$$

      examples: 55533 33777799992 2555, 777666877 77777 7833 3366 $$\in \gamma$$
        777444777744422266677733 388222844433 $$\not\in \gamma$$
    • $$\delta = \{ m \in \mathcal{M}\,|\,$$ each digit of $$m'$$ is equal to the previous or the next digit (or both) $$\}$$

      examples: 3366 666777 7777883 3 33777 $$\in \delta$$
        77778666 666 68882 27778 88444 4 $$\not\in \delta$$

    Use a command from the grep family to select only those lines from the file multitap.txt2 whose multitap sequence belongs to the given set.

  2. Consider the sets $$\alpha$$, $$\beta$$, $$\gamma$$ and $$\delta$$ as defined above. Now, use these sets to find out the secret message that is composed of the following four words:

    • The first word is on the unique line with the multitap sequence belonging to $$\alpha \cap \beta$$

    • The second word is on the unique line with the multitap sequence belonging to $$\beta \cap \gamma$$

    • The third word is on the unique line with the multitap sequence belonging to $$\gamma \cap \delta$$

    • The fourth word is on the unique line with the multitap sequence belonging to $$\delta \cap \alpha$$

    Indicate the Unix command (or command sequence) that was used to find each word. It is prohibited to literally enter the word (e.g.: echo xxx).