PROG0481 - Hearing places

no tags 

Thomas Stedman Whitwell (1784-1840) was an English architect and civil engineer, best known for his design of the secular communal utopia at New Harmony, Indiana, USA. This was done in close collaboration with the mill owner and social reformer Robert Owen, but their plans remained unrealized.

Whitwell's short stay at New Harmony allowed him to publish in the New Harmony Gazette a proposal for a new system of town naming according to their position. Whitwell thought it illogical and confusing that different towns sometimes have the same name. He suggested assigning each city a unique name that was composed of two words separated by a space. The first word corresponds to the latitude of the city, and the second word to its longitude. Latitude and longitude were converted to words by traversing each coordinate from left to right and converting each digit to the corresponding letters in this table Whitwell published in the New Harmony Gazette in 1826.

1 2 3 4 5 6 7 8 9 0
a e i o u y ee ei ie ou
b d f k l m n p r t

Selection of letters alternates between the first and second rows of the table, which guarantees that the generated words have alternating consonants and vowels. Words that correspond to latitudes in the southern hemisphere start with an S, and words corresponding to western longitudes start with a V. No extra letter is added at the beginning of the words corresponding to north latitudes and east longitudes, so that these words start with a vowel.

Thus New Harmony (USA; 38°11'N, 87°55'W) would be rechristened Ipab Veinul. Washington DC (USA; 38°90'N, 77°04'W) would become Ipiet Veenouk, Brussels (Belgium; 50°85'N, 4°35'O) would be Uteil Ofu, Kampala (Uganda; 0°32'N, 32°58'O) would be Oufe Idup and Buenos Aires (Argentina; 34°61'Z, 58°38'O) would be Sikyb Upip. What these names lack in poetry they make up in utility: a traveler given the name of a town can immediately infer its location. Unfortunately, Whitwell’s scheme never caught on — and today the United States has 28 Springfields, 29 Clintons, and 30 Franklins.

Assignment

Determine a city's name based on its position according to Thomas Stedman Whitwell's scheme. In order to do so, you have to

  • Write a function digit2letters that takes an integer argument. The function must return the letters (string) that correspond to the given integer in the table used in Whitwell's scheme. By default, the function returns the letters (consonants) found at the first row of the table. However, if the value False is passed to the second optional parameter first, the function must return the corresponding letter found at the second row of the table (a vowel). Try to minimize the number of conditions that need to be tested in calling the function.
  • Use the function digit2letters to write a function coord2word that takes the latitude or longitude as its argument. This coordinate must be passed as a string using the format d°m'w. Here, d represents a number of degrees, m a number of minutes and w a wind direction: N for north, S for south, W for west or E for east. The function must return the word (string) that corresponds to the given coordinate according to Whitwell's scheme. This word must start with an uppercase letter, followed by a series of lowercase letters. 
  • Use the function coord2word to write a function placename that takes one or two strings that indicate the position of a city. If two strings are passed to the function, they respectively represent the latitude and longitude of the city. If only a single string is passed to the function, it should contain both the latitude and the longitude of the city, separated by a comma. The same format as used with the function coord2word is used described the latitude and longitude. Whitespace (spaces, tabs, newlines, …) in the strings passed to the function placename must be ignored. The function must return the city's name according to Whitwell's scheme, based on the given latitude and longitude of the city.

Example

>>> digit2letters(3)
'i'
>>> digit2letters(7, False)
'n'
>>> digit2letters(0, first=False)
't'

>>> coord2word("38°11'N")
'Ipab'
>>> coord2word("87°55'W")
'Veinul'

>>> placename("38°11'N", "87°55'W")   # New Harmony
'Ipab Veinul'
>>> placename("38°11'N, 87°55'W")     # New Harmony
'Ipab Veinul'
>>> placename("38°90'N", "77°04'W")   # Washington DC (VSA)
'Ipiet Veenouk'
>>> placename("50°85'N, 4°35'E")      # Brussels (Belgium)
'Uteil Ofu'
>>> placename("0°32'N", "32°58'E")    # Kampala (Uganda)
'Oufe Idup'
>>> placename("34°61'S, 58°38'E")     # Buenos Aires (Argentina)
'Sikyb Upip'

Thomas Stedman Whitwell (1784-1840) was een Engelse architect die voornamelijk bekendheid verwierf met zijn ontwerp voor de seculiere utopische stadsontwikkeling van New Harmony, Indiana, VSA. Hij werkte hiervoor nauw samen met de sociale hervormer Robert Owen, maar hun plannen werden nooit gerealiseerd.

Tijdens zijn korte verblijf in New Harmony publiceerde de New Harmony Gazette in 1826 ook een voorstel van Stedman Whitwell om plaatsnamen te laten afhangen van hun ligging. Whitwell vond het immers onlogisch en verwarrend dat verschillende steden soms dezelfde naam droegen. In dit voorstel kreeg elke stad een unieke naam bestaande uit twee woorden, die van elkaar gescheiden worden door één enkele spatie. Het eerste woord correspondeert met de breedteligging van de stad, en het tweede woord met diens lengteligging. De breedte- en lengtegraad worden omgezet naar een woord door de karakters van de coördinaat van links naar rechts te doorlopen en elk cijfer om te zetten naar de letters die ermee corresponderen in onderstaande tabel.

1 2 3 4 5 6 7 8 9 0
a e i o u y ee ei ie ou
b d f k l m n p r t

Hierbij worden alternerend letters geselecteerd uit de eerste en tweede rij van de tabel. Dit garandeert dat de woorden achtereenvolgens bestaan uit klinkers en medeklinkers. Voor breedtegraden in het zuiden begint het corresponderende woord altijd met een S, en voor lengtegraden in het westen begint het woord altijd met een V. Voor breedtegraden in het noorden of lengtegraden in het oosten wordt er vooraan geen extra letter toegevoegd, en beginnen de woorden dus met een klinker.

Op die manier wordt New Harmony (VSA; 38°11'N, 87°55'W) bijvoorbeeld omgedoopt tot Ipab Veinul. Washington DC (VSA; 38°90'N, 77°04'W) wordt Ipiet Veenouk, Brussel (België; 50°85'N, 4°35'O) wordt Uteil Ofu, Kampala (Ugana; 0°32'N, 32°58'O) wordt Oufe Idup en Buenos Aires (Argentinië; 34°61'Z, 58°38'O) wordt Sikyb Upip. Ook al klinken deze namen niet bijzonder poëtisch, ze zijn zeker handig: als een reiziger bij een stad aankomt, dan kan hij op basis van diens naam onmiddellijk de ligging te weten komen. Spijtig genoeg sloeg het naamgevingsschema van Whitwell nooit aan — hierdoor telt de Verenigde Staten van Amerika op vandaag 28 Springfields, 29 Clintons en 30 Franklins.

Opgave

Bepaal op basis van de ligging van een stad zijn naam volgens het schema van Thomas Stedman Whitwell. Hiervoor ga je als volgt te werk:

  • Schrijf een functie cijfer2letters waaraan een cijfer (integer) moet doorgegeven worden. De functie moet de letters (string) teruggeven die corresponderen met het gegeven cijfer volgens de tabel die gebruikt wordt in het schema van Whitwell. Standaard worden de corresponderende letters op de eerste rij (klinkers) teruggegeven, maar als aan de tweede optionele parameter eerste van de functie de waarde False wordt doorgegeven, dan moet de functie de corresponderende letter op de tweede rij (een medeklinker) teruggeven. Probeer het aantal voorwaarden die moeten getest worden bij het uitvoeren van de functie tot een minimum te beperken.
  • Gebruik de functie cijfer2letters om een functie coord2woord te schrijven waaraan een breedte- of lengtegraad moet doorgegeven worden. Deze coördinaat wordt doorgegeven als een string van de vorm g°m'w. Hierbij stelt g een aantal graden voor, m een aantal minuten en w een windrichting: N voor het noorden, Z voor het zuiden, W voor het westen of O voor het oosten. De functie moet het woord (string) teruggeven dat correspondeert met de gegeven coördinaat volgens het schema van Whitwell. Dit woord moet beginnen met een hoofdletter, en bestaat voor de rest enkel uit kleine letters.
  • Gebruik de functie coord2woord om een functie plaatsnaam te schrijven waaraan één of twee strings moeten doorgegeven worden die de ligging van een stad aangeven. Indien er twee strings aan de functie doorgegeven worden, dan stellen deze respectievelijk de breedte- en lengtegraad van de stad voor. Indien er slechts één string aan de functie wordt doorgegeven, dan moet die string zowel de breedte- en lengtegraad van de stad bevatten, van elkaar gescheiden door een komma. Voor de omschrijving van breedte- en lengtegraden wordt opnieuw het formaat gebruikt zoals beschreven bij de functie coord2woord. Als de strings die aan de functie plaatsnaam doorgegeven worden witruimte (spaties, tabs, regeleindes) bevatten, dan moet die witruimte genegeerd worden. De functie moet de naam van de stad teruggeven volgens het schema van Whitwell, op basis van de gegeven breedte- en lengteligging van de stad.

Voorbeeld

>>> cijfer2letters(3)
'i'
>>> cijfer2letters(7, False)
'n'
>>> cijfer2letters(0, eerste=False)
't'

>>> coord2woord("38°11'N")
'Ipab'
>>> coord2woord("87°55'W")
'Veinul'

>>> plaatsnaam("38°11'N", "87°55'W")   # New Harmony
'Ipab Veinul'
>>> plaatsnaam("38°11'N, 87°55'W")     # New Harmony
'Ipab Veinul'
>>> plaatsnaam("38°90'N", "77°04'W")   # Washington DC (VSA)
'Ipiet Veenouk'
>>> plaatsnaam("50°85'N, 4°35'O")      # Brussel (België)
'Uteil Ofu'
>>> plaatsnaam("0°32'N", "32°58'O")    # Kampala (Uganda)
'Oufe Idup'
>>> plaatsnaam("34°61'Z, 58°38'O")     # Buenos Aires (Argentinië)
'Sikyb Upip'


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