Abbreviations, automatic: Difference between revisions

Content added Content deleted
(→‎{{header|Kotlin}}: Changed code so that lines are now printed as soon as they're processed)
(→‎{{header|Perl 6}}: Refactor into a reusable subroutine rather than hard coding list. Add a line counter. Adjust output displayed to show infinite abbreviation)
Line 283: Line 283:
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2017.08}}
{{works with|Rakudo|2017.08}}
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.
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> for './DoWAKA.txt'.IO.lines {
<lang perl6>sub auto-abbreviate ( $string ) {
my @days = .words;
return Nil unless my @days = $string.words;
my $max = @days».chars.max;
my $max = @days».chars.max;
for 0 .. $max {
for 0 .. $max {
say "$_: {@days}" and last if +@days».substr(0, $_).Set == 7;
return "$_: {@days}" if +@days».substr(0, $_).Set == 7;
say "∞: {@days}" and last if $_ == $max;
return "∞: {@days}" if $_ == $max;
}
}
}
}</lang>

# Testing
say ++$, ') ', .&auto-abbreviate for './DoWAKA.txt'.IO.line</lang>
{{out|Sample abbreviated (heh) output}}
{{out|Sample abbreviated (heh) output}}
<pre>2: Sunday Monday Tuesday Wednesday Thursday Friday Saturday
<pre>1) 2: Sunday Monday Tuesday Wednesday Thursday Friday Saturday
2: Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag
2) 2: Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag
4: E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë
3) 4: E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë
2: Ehud Segno Maksegno Erob Hamus Arbe Kedame
4) 2: Ehud Segno Maksegno Erob Hamus Arbe Kedame
5: Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit
5) 5: Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit

4: Guiragui Yergou_shapti Yerek_shapti Tchorek_shapti Hink_shapti Ourpat Shapat
2: domingu llunes martes miércoles xueves vienres sábadu
2: Bazar_gÜnÜ Birinci_gÜn Çkinci_gÜn ÜçÜncÜ_gÜn DÖrdÜncÜ_gÜn Bes,inci_gÜn Altòncò_gÜn
6: Igande Astelehen Astearte Asteazken Ostegun Ostiral Larunbat
4: Robi_bar Shom_bar Mongal_bar Budhh_bar BRihashpati_bar Shukro_bar Shoni_bar
2: Nedjelja Ponedeljak Utorak Srijeda Cxetvrtak Petak Subota
5: Disul Dilun Dimeurzh Dimerc'her Diriaou Digwener Disadorn
2: nedelia ponedelnik vtornik sriada chetvartak petak sabota
∞: sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk sing_kei_yat
4: Diumenge Dilluns Dimarts Dimecres Dijous Divendres Dissabte
16: Dzeenkk-eh Dzeehn_kk-ehreh Dzeehn_kk-ehreh_nah_kay_dzeeneh Tah_neesee_dzeehn_neh Deehn_ghee_dzee-neh Tl-oowey_tts-el_dehlee Dzeentt-ahze
...
...

4: djadomingu djaluna djamars djarason djaweps djabièrnè djasabra
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Ü
2: Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
91) 2: Sun Moon Mars Mercury Jove Venus Saturn
</pre>
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}}==
=={{header|REXX}}==