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.
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.
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:
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: | |
$$\beta = \{ m \in \mathcal{M}\,|\,$$ consecutive digits of $$m'$$ form an increasing series $$\}$$
examples: | |
$$\gamma = \{ m \in \mathcal{M}\,|\,$$ $$m'$$ contains at least 2 series of at least 4 consecutive equal digits $$\}$$
examples: | |
$$\delta = \{ m \in \mathcal{M}\,|\,$$ each digit of $$m'$$ is equal to the previous or the next digit (or both) $$\}$$
examples: | |
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.
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).