Separate the house number from the street name: Difference between revisions

m
Category:Web / <lang python>
m (use normal emphasis)
m (Category:Web / <lang python>)
Line 1:
{{Draft task}} [[Category:Web]]
{{Template:Clarify task}}
In Germany and the Netherlands postal addresses have the form: street name, followed by the house number, in accordance with the national standards DIN 5008 respectively NEN 5825. The problem is that some street names have numbers (e.g. special years) and some [http://en.wikipedia.org/wiki/House_numbering#Europe house numbers] have characters as an extension. It's a real life problem and difficult because in the Netherlands some street names are a tribute to our liberators. The street names have the numbers 40 and 45 indicating the years of war between 1940 and 1945.
;Task:
 
Write code that correctly separates the house number from the street name and presents them both. <em>No static data must be shown, only processed data.</em>
and presents them both.
<em>No static data must be shown, only processed data.</em>
* For bonus Kudos: Make the splitting also valid for more countries.
 
The test-set:
<pre>Plataanstraat 5
Line 43 ⟶ 46:
=={{header|J}}==
 
'''Solution''':<lang j>special=: '4',.'012345'
<lang j>special=: '4',.'012345'
digit=: '0123456789'
 
Line 155 ⟶ 159:
 
=={{header|Perl 6}}==
An unquestioning translation of the Scala example's regex to show how we lay out such regexes for readability in Perl 6, except that we take the liberty of leaving the space out of the house number. (Hard constants like 1940 and 1945 are a code smell, and the task should probably not require such constants unless there is a standard to point to that mandates them.) So expect this solution to change if the task is actually defined reasonably, such as by specifying that four-digit house numbers are excluded in Europe. (In contrast, four- and five-digit house numbers are not uncommon in places such as the U.S. where each block gets a hundred house numbers to play with, and there are cities with hundreds of blocks along a street.)
(Hard constants like 1940 and 1945 are a code smell,
and the task should probably not require such constants unless there is a standard to point to that mandates them.)
So expect this solution to change if the task is actually defined reasonably, such as by specifying that four-digit house numbers are excluded in Europe.
(In contrast, four- and five-digit house numbers are not uncommon
in places such as the U.S. where each block gets a hundred house numbers
to play with, and there are cities with hundreds of blocks along a street.)
<lang perl6>say m[
( .*? )
Line 304 ⟶ 314:
 
=={{header|Python}}==
<!-- ?? missing code ?? -->
<lang python>
Plataanstraat 5 split as (Plataanstraat, 5)
Straat 12 split as (Straat, 12)
Line 382 ⟶ 394:
 
adressen.foreach(s => println(f"$s%-25s split as ${splitsAdressen(s)}"))
}</lang>{{out}}
{{out}}
<pre>Plataanstraat 5 split as (Plataanstraat, 5)
Straat 12 split as (Straat, 12)
Anonymous user