PROG0277 - Mobile synonyms

The alphabet has 26 letters, whereas the keypad of a mobile phone or GPS device usually has far less keys. The multi-tap technique was one of the first methods used to enter text messages on such devices. The idea is quite simple: the letters of the alphabet are printed in groups of three or four under each key, beginning on the 2-key (2=ABC, 3=DEF, 4=GHI, 5=JKL, 6=MNO, 7=PQRS, 8=TUV, 9=WXYZ). The technique is then used by repeatedly pressing the same key to cycle through the letters corresponding to that key. In order to enter the letter A, for example, the 2-key must be pressed once. If you want to enter the letter B, the same 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. This allows to enter two letters that are mapped on the same key.

MultiTab toetsenbord
Arrangement of the letters on a modern telephone keypad, as used for text messaging.

The T9 technique is an improvement over the multi-tap technique, originally developed by Tegic Communications. The name of the technique stands for Text on 9 keys, and it is a patented predictive text technology for mobile phones. T9 allows words to be entered by a single keystroke for each letter, as opposed to the multi-tap approach used in conventional phone text entry. For example, the word Banner can be entered with the following sequence of keystrokes: 2 (ABC), 2 (ABC), 6 (MNO), 6 (MNO), 3 (DEF) and 7 (PQRS). The T9 system looks up all possible words corresponding to the sequence of keystrokes in a built-in dictionary. If there are multiple possibilities, the user needs to select the intended word from a list. This usually works a lot faster than entering the individual letters using multi-tap. Two words corresponding to the same sequence of keystrokes with the T9 technique are called mobile synonyms.

Assignment

  1. Write a function T9 that takes a single string argument containing only letters. The function must return the sequence of keystrokes that needs to be entered on a mobile phone keypad supporting T9 in order to enter the given word. The function should handle the given word case-insensitively.
  2. Use the function T9 in order to write a function mobileSynonyms that takes two string arguments representing words that only contain letters. The function should return a Boolean value that indicates whether or not the two given words are mobile synonyms.

Example

>>> T9('Banner')
'226637'
>>> T9('succes')
'782237'
>>> T9('rubber')
'782237'

>>> mobileSynonyms('succes', 'rubber')
True
>>> mobileSynonyms('Monday', 'Friday')
False

Het alfabet bestaat uit 26 karakters, terwijl het toetsenbord van een mobiele telefoon of een GPS doorgaans veel minder toetsen bevat. Om op dergelijke toestellen toch makkelijk woorden te kunnen intoetsen, werd oorspronkelijk gebruik gemaakt van de zogenaamde MultiTap techniek. Het principe is eenvoudig: op elke toets worden drie of meer letters afgebeeld (2=ABC, 3=DEF, 4=GHI, 5=JKL, 6=MNO, 7=PQRS, 8=TUV, 9=WXYZ). Om de gewenste letter te krijgen, moet je de toets waarop de letter wordt afgebeeld één of meer keer indrukken, afhankelijk van de positie van de letter op de toets. Stel dat je bijvoorbeeld de letter A wilt typen. Dan moet je één keer op toets 2 drukken. Wil je echter een B typen, dan moet je twee keer kort na elkaar op toets 2 drukken. Om na elkaar twee letters te typen die op dezelfde toets worden afgebeeld, moet de gebruiker een korte pauze inlassen alvorens dezelfde toets opnieuw in te drukken.

MultiTab toetsenbord
De schikking van de letters op de toetsen van een GSM-toestel.

De T9 techniek is een verbetering op MultiTap die werd ontwikkeld door Tegic Communications. De naam van de techniek staat voor Tekst op 9 toetsen, en wordt ook predictive text genoemd. In tegenstelling tot MultiTap moet je bij T9 slechts één keer op de toets drukken van de letter die je nodig hebt. Wil je bijvoorbeeld de tekst Hallo intypen, dan druk je achtereenvolgens één keer op de volgende toetsen: 4 (GHI), 2 (ABC), 5 (JKL), 5 (JKL) en tenslotte 6 (MNO). Het T9-systeem zal daarna in het ingebouwde woordenboek zoeken naar alle mogelijke woorden die met deze cijfercombinatie kunnen gevormd worden. Indien er meerder mogelijkheden zijn, dan moet de gebruiker het bedoelde woord uit de lijst kiezen. Dit werkt doorgaans een stuk sneller dan het kiezen van de individuele letters via MultiTap. Twee woorden die corresponderen met dezelfde cijfercombinatie worden GSMoniemen genoemd.

Opgave

  1. Schrijf een functie T9 waaraan een string moet doorgegeven worden die enkel bestaat uit letters. Deze functie moet als resultaat een string teruggeven met de cijfercombinatie die je moet ingeven op een GSM-toestel dat het T9-systeem ondersteunt. Hierbij mag de functie geen onderscheid maken tussen hoofdletters en kleine letters.
  2. Gebruik de functie T9 om een functie GSMoniemen te schrijven waaraan twee strings als argument moeten doorgegeven worden. Deze functie moet als resultaat een Booleaanse waarde teruggeven die aangeeft of de gegeven strings GSMoniemen zijn of niet.

Voorbeeld

>>> T9('Hallo')
'42556'
>>> T9('aanbod')
'226263'
>>> T9('bamboe')
'226263'

>>> GSMoniemen('aanbod', 'bamboe')
True
>>> GSMoniemen('maandag', 'vrijdag')
False

Added by:Peter Dawyndt
Date:2012-08-27
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.