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

m
Moved static data out of example and into solution to comply with highlighted task requirement.
(Flagged for clarification.)
m (Moved static data out of example and into solution to comply with highlighted task requirement.)
Line 42:
 
=={{header|J}}==
 
{{incorrect|J}}
'''Solution''' (''native''):<lang j> din5008 =: split~ i.&1@:e.&'0123456789'</lang>
'''Solution''' (''regex''):<lang j> require'regex'
din5008 =: split~ [: {.@, '\d'&rxmatch</lang>
 
'''Example''':<lang j> din5008"1 ];._2 noun define
Straat 12
Straat 12 II
Line 80:
Schmidener Weg 3
Karl-Weysser-Str. 6
)</lang>
)
 
'''Example''':<lang j>
+------------------+-----------------------+
|Straat |12 |
Line 147 ⟶ 149:
+------------------+-----------------------+</lang>
'''Notes''':I'm jumping on this task very early in its development; at the moment, it lacks explicit rules for identifying the location where the house number begins. So, since I don't read German or Dutch, pending more explicit rules, I'm going to assume the number starts at the first decimal digit in the string and continues to the end, and that everything preceding that point is considered the street name.
 
=={{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.)
6,962

edits