Jump to content

Abbreviations, automatic: Difference between revisions

m
→‎{{header|Perl 6}}: move string building out of the sub (separation of concerns)
m (removed the __TOC__ (no longer needed).)
m (→‎{{header|Perl 6}}: move string building out of the sub (separation of concerns))
Line 282:
Saving the "Days of Week, Also Known As" table to a local file DoWAKA.txt. Note: lines that have duplicate day names will get ∞ as the minimum number of characters, as there in no amount of characters that can be entered to distinguish the days uniquely. It is somewhat unclear as to what is meant by "return a null string". I have chosen to return Nil.
 
<lang perl6>sub auto-abbreviate ( Str $string ) {
return Nil unless my @days = $string.words;
my $max = @days».chars.max;
for 0 .. $max {
return "$_: {@days}" if +@days».substr(0, $_).Set == 7;
return "': {@days}" ' if $_ == $max;
}
}
 
# Testing
say ++$, ') ', .&auto-abbreviate, ' ', $_ for './DoWAKA.txt'.IO.linelines;</lang>
{{out|Sample abbreviated (heh) output}}
<pre>1) 2: Sunday Monday Tuesday Wednesday Thursday Friday Saturday
2) 2: Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag
3) 4: E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë
4) 2: Ehud Segno Maksegno Erob Hamus Arbe Kedame
5) 5: Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit
 
...
 
90) ∞: Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_gÜnÜ
91) 2: Sun Moon Mars Mercury Jove Venus Saturn
92) 2: zondag maandag dinsdag woensdag donderdag vrijdag zaterdag
93) 2: KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa
94) 5: Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend
95) 1: Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado
96) 7: Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum
97) 12: xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù
98) 4: djadomingu djaluna djamars djarason djaweps djabièrnè djasabra
99) 2: Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau</pre>
 
=={{header|REXX}}==
10,351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.