Abbreviations, automatic: Difference between revisions
m added a related task. |
→{{header|Python}}: Added a variant (functional composition) |
||
Line 1,443:
=={{header|Python}}==
===Imperative===
{{works with|Python|3.6}}
{{trans|Kotlin}}
Line 1,576 ⟶ 1,577:
2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
</pre>
===Functional===
<lang python>import itertools
# abbrevLen :: [String] -> Int
def abbrevLen(xs):
n = len(xs)
return next(
len(a[0]) for a in map(
lambda x: nub(map(lambda y: ''.join(y), x)),
transpose(map(inits, xs))
) if n == len(a)
)
# TEST ----------------------------------------------------
def main():
xs = list(map(strip, lines(
readFile('weekDayNames.txt')
)))
for i, n in enumerate(map(compose(abbrevLen)(words), xs)):
print (n, ' ', xs[i])
# GENERIC -------------------------------------------------
# compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
return lambda f: lambda x: g(f(x))
# inits :: [a] -> [[a]]
def inits(xs):
return scanl(lambda a, x: a + [x])(
[]
)(list(xs))
# lines :: String -> [String]
def lines(s):
return s.splitlines()
# nub :: [a] -> [a]
def nub(xs):
return list(dict.fromkeys(xs))
# readFile :: FilePath -> IO String
def readFile(fp):
return open(fp).read()
# scanl is like reduce, but returns a succession of
# intermediate values, building from the left.
# scanl :: (b -> a -> b) -> b -> [a] -> [b]
def scanl(f):
return lambda a: lambda xs: (
list(itertools.accumulate([a] + list(xs), f))
)
# strip :: String -> String
def strip(s):
return s.strip()
# transpose :: [[a]] -> [[a]]
def transpose(xs):
return list(map(list, zip(*xs)))
# words :: String -> [String]
def words(s):
return s.split()
# MAIN ---
if __name__ == '__main__':
main()</lang>
{{Out}}
<pre>2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday
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ë
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
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</pre>
=={{header|REXX}}==
|
Revision as of 00:01, 4 November 2018
![Task](http://static.miraheze.org/rosettacodewiki/thumb/b/ba/Rcode-button-task-crushed.png/64px-Rcode-button-task-crushed.png)
You are encouraged to solve this task according to the task description, using any language you may know.
The use of abbreviations (also sometimes called synonyms, nicknames, AKAs, or aliases) can be an
easy way to add flexibility when specifying or using commands, sub─commands, options, etc.
It would make a list of words easier to maintain (as words are added, changed, and/or deleted) if
the minimum abbreviation length of that list could be automatically (programmatically) determined.
For this task, use the list (below) of the days-of-the-week names that are expressed in about a hundred languages (note that there is a blank line in the list).
Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sondag Maandag Dinsdag Woensdag Donderdag Vrydag Saterdag E_djelë E_hënë E_martë E_mërkurë E_enjte E_premte E_shtunë Ehud Segno Maksegno Erob Hamus Arbe Kedame Al_Ahad Al_Ithinin Al_Tholatha'a Al_Arbia'a Al_Kamis Al_Gomia'a Al_Sabit Guiragui Yergou_shapti Yerek_shapti Tchorek_shapti Hink_shapti Ourpat Shapat domingu llunes martes miércoles xueves vienres sábadu 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 Igande Astelehen Astearte Asteazken Ostegun Ostiral Larunbat Robi_bar Shom_bar Mongal_bar Budhh_bar BRihashpati_bar Shukro_bar Shoni_bar Nedjelja Ponedeljak Utorak Srijeda Cxetvrtak Petak Subota Disul Dilun Dimeurzh Dimerc'her Diriaou Digwener Disadorn nedelia ponedelnik vtornik sriada chetvartak petak sabota sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk Diumenge Dilluns Dimarts Dimecres Dijous Divendres Dissabte 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-ahzee dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee s0ndag mandag tirsdag onsdag torsdag fredag l0rdag zondag maandag dinsdag woensdag donderdag vrijdag zaterdag Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai dimanche lundi mardi mercredi jeudi vendredi samedi Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon Domingo Segunda_feira Martes Mércores Joves Venres Sábado k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar vasárnap hétfö kedd szerda csütörtök péntek szombat Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur sundio lundio mardio merkurdio jovdio venerdio saturdio Minggu Senin Selasa Rabu Kamis Jumat Sabtu Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn domenica lunedí martedí mercoledí giovedí venerdí sabato Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam Jabot Manre Juje Wonje Taije Balaire Jarere geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu sφndag mandag tirsdag onsdag torsdag fredag lφrdag lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte djadomingo djaluna djamars djarason djaweps djabièrna djasabra Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado Domingo Lunes martes Miercoles Jueves Viernes Sabado Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne nedjelja ponedjeljak utorak sreda cxetvrtak petak subota Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- nedel^a pondelok utorok streda s^tvrtok piatok sobota Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota domingo lunes martes miércoles jueves viernes sábado sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi söndag måndag tisdag onsdag torsdag fredag lordag Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi nedilya ponedilok vivtorok sereda chetver pyatnytsya subota Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo zuntik montik dinstik mitvokh donershtik fraytik shabes iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ Sun Moon Mars Mercury Jove Venus Saturn zondag maandag dinsdag woensdag donderdag vrijdag zaterdag KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù djadomingu djaluna djamars djarason djaweps djabièrnè djasabra Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Caveat: The list (above) most surely contains errors (or, at the least, differences) of what the actual (or true) names for the days-of-the-week.
To make this Rosetta Code task page as small as possible, if processing the complete list, read the days-of-the-week from a file (that is created from the above list).
Notes concerning the above list of words
- each line has a list of days-of-the-week for a language, separated by at least one blank
- the words on each line happen to be in order, from Sunday ──► Saturday
- most lines have words in mixed case and some have all manner of accented words and other characters
- some words were translated to the nearest character that was available to code page 437
- the characters in the words are not restricted except that they may not have imbedded blanks
- for this example, the use of an underscore (_) was used to indicate a blank in a word
- Task
-
- The list of words (days of the week) needn't be verified/validated.
- Write a function to find the (numeric) minimum length abbreviation for each line that would make abbreviations unique.
- A blank line (or a null line) should return a null string.
- Process and show the output for at least the first five lines of the file.
- Show all output here.
- Related tasks
AWK
<lang AWK>
- syntax: GAWK -f ABBREVIATIONS_AUTOMATIC.AWK ABBREVIATIONS_AUTOMATIC.TXT
{ dow_arr[NR] = $0 } END {
for (i=1; i<=NR; i++) { if (split(dow_arr[i],arr1,FS) != 7) { printf("NG %s\n",dow_arr[i]) continue } col_width = 0 for (j=1; j<=7; j++) { col_width = max(col_width,length(arr1[j])) } for (col=1; col<=col_width; col++) { delete arr2 for (j=1; j<=7; j++) { arr2[toupper(substr(arr1[j],1,col))] } if (length(arr2) == 7) { break } if (col >= col_width) { # catches duplicate day names col = "NG" break } } printf("%2s %s\n",col,dow_arr[i]) } exit(0)
} function max(x,y) { return((x > y) ? x : y) } </lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev NG 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ¦ridjudagur Midvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sfndag mandag tirsdag onsdag torsdag fredag lfrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 2 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
C#
<lang csharp>using System; using System.Collections.Generic;
namespace Abbreviations {
class Program { static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLines("days_of_week.txt"); int i = 0;
foreach (string line in lines) { i++; if (line.Length > 0) { var days = line.Split(); if (days.Length != 7) { throw new Exception("There aren't 7 days in line " + i); }
Dictionary<string, int> temp = new Dictionary<string, int>(); foreach (string day in days) { if (temp.ContainsKey(day)) { Console.WriteLine(" ∞ {0}", line); continue; } temp.Add(day, 1); }
int len = 1; while (true) { temp.Clear(); foreach(string day in days) { string key; if (len < day.Length) { key = day.Substring(0, len); } else { key = day; } if (temp.ContainsKey(key)) { break; } temp.Add(key, 1); } if (temp.Count == 7) { Console.WriteLine("{0,2:D} {1}", len, line); break; } len++; } } } } }
}</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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‰ 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi MŠkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^l¡ £ter˜ str^eda c^tvrtek p tek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Ja—do Vendredo Sabato 1 pšhap„ev esmasp„ev teisip„ev kolmap„ev neljap„ev reede laup„ev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur m nadagur t˜sdaguy mikudagur h¢sdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes M‚rcores Joves Venres S bado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 p¢pule p¢`akahi p¢`alua p¢`akolu p¢`ah p¢`alima p¢`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vas rnap h‚tf” kedd szerda cst”rt”k p‚ntek szombat 2 Sunnudagur M nudagur Æriëjudagur Miëvikudagar Fimmtudagur F™studagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 D‚_Domhnaigh D‚_Luain D‚_M irt D‚_Ceadaoin D‚_ardaoin D‚_hAoine D‚_Sathairn 2 domenica luned¡ marted¡ mercoled¡ gioved¡ venerd¡ sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lun‘ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_r xing-_qi-_yi-. xing-_qi-_Šr xing-_qi-_san-. xing-_qi-_s xing-_qi-_wuv. xing-_qi-_li— 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo min•mishi m rtes miŠrkoles misheushi bŠrnashi mish baro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 síndag mandag tirsdag onsdag torsdag fredag lírdag 7 lo_dimenge lo_diluns lo_dimar‡ lo_dimŠrcres lo_dij•us lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabiŠrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire ter‡a-feire quarta-feire quinta-feire sexta-feira s†bado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminic¦ Luni Mart'i Miercuri Joi Vineri Sƒmb¦t¦ 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-m…irt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes mi‚rcoles jueves viernes s bado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 s”ndag m†ndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 L‚-p…i-j¡t P…i-it P…i-j‹ P…i-sa¤ P…i-s P…i-g™. P…i-l k 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali €ar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhƒ.t Th£*_Hai Th£*_Ba Th£*_Tu* Th£*_Na'm Th£*_S u Th£*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lun‘ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gšnš Bazar_‘rt‘si €‘rs,‘nb‘_axs,am• €‘rs,‘nb‘_gšnš Cšm‘_axs,am• Cšm‘_gšnš Cšm‘_Senb‘ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres S bado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_ti…n xing-_qi-_yi-. xing-_qi-_Šr xing-_qi-_san-. xing-_qi-_s xing-_qi-_wuv. xing-_qi-_li— 4 djadomingu djaluna djamars djarason djaweps djabiŠrnŠ djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
D
<lang D>import std.conv; import std.exception; import std.range; import std.stdio; import std.string;
void main() {
foreach (size_t i, dstring line; File("days_of_week.txt").lines) { line = chomp(line); if (!line.empty) { auto days = line.split; enforce(days.length==7, text("There aren't 7 days in line ", i+1));
int[dstring] temp; foreach(day; days) { temp[day]++; } if (days.length < 7) { writeln(" ∞ ", line); continue; } int len = 1; while (true) { temp.clear(); foreach (day; days) { temp[day.take(len).array]++; } if (temp.length == 7) { writefln("%2d %s", len, line); break; } len++; } } }
}</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
F#
The function
<lang fsharp> let fN g=let rec fN n=if g|>List.map(fun(g:string)->g.[0..n])|>Set.ofList|>Set.count=(List.length g) then (n+1) else fN(n+1)
fN 0
</lang>
The Task - Demonstrate the function
<lang fsharp> fN ["Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday"; "Friday"; "Saturday"] // -> 2 fN ["Sondag"; "Maandag"; "Dinsdag"; "Woensdag"; "Donderdag"; "Vrydag"; "Saterdag"] // -> 2 fN ["E_djelë"; "E_hënë"; "E_martë"; "E_mërkurë"; "E_enjte"; "E_premte"; "E_shtunë"] // -> 4 fN ["Ehud"; "Segno"; "Maksegno"; "Erob"; "Hamus"; "Arbe"; "Kedame"] // -> 2 fN ["Al_Ahad"; "Al_Ithinin"; "Al_Tholatha'a"; "Al_Arbia'a"; "Al_Kamis"; "Al_Gomia'a"; "Al_Sabit";] // -> 5 </lang>
Factor
Part of Factor's philosophy is to write extremely short words (functions). As a guideline, words should usually fit on one to three 64-column lines unless they use cond
or contain a large literal. If you find yourself writing a word longer than that, it's time to factor!
As a concatenative language, Factor is uniquely suited for factoring words into smaller words. Assuming lexical/dynamic variables are not used, factoring is a cut-and-paste job that can be performed almost anywhere there is whitespace.
<lang factor>USING: formatting io io.encodings.utf8 io.files kernel math sequences sets splitting ; IN: rosetta-code.abbreviations-automatic
- map-head ( seq n -- seq' ) [ short head ] curry map ;
- unique? ( seq n -- ? ) map-head all-unique? ;
- (abbr-length) ( seq -- n )
1 [ 2dup unique? ] [ 1 + ] until nip ;
- abbr-length ( str -- n/str )
[ "" ] [ " " split (abbr-length) ] if-empty ;
- show ( str -- ) dup abbr-length swap " %2u %s\n" printf ;
- labels ( -- )
"Min." "abbr" "Days of the week" "%s\n%s%32s\n" printf ;
- line ( n -- ) [ "=" write ] times ;
- header ( -- ) labels 4 line bl 75 line nl ;
- body ( -- ) [ show ] each-line ;
- abbreviations ( -- )
header "day-names.txt" utf8 [ body ] with-file-reader ;
MAIN: abbreviations</lang>
- Output:
Min. abbr Days of the week ==== =========================================================================== 2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev "" 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Go
<lang go>package main
import(
"bufio" "fmt" "os" "strings"
)
func distinctStrings(strs []string) []string {
len := len(strs) set := make(map[string]bool, len) distinct := make([]string, 0, len) for _, str := range strs { if !set[str] { distinct = append(distinct, str) set[str] = true } } return distinct
}
func takeRunes(s string, n int) string {
i := 0 for j := range s { if i == n { return s[:j] } i++ } return s
}
func main() {
file, err := os.Open("days_of_week.txt") if err != nil { fmt.Println("Unable to open file.") return } defer file.Close() reader := bufio.NewReader(file) lineCount := 0 for { line, err := reader.ReadString('\n') if err != nil { // end of file reached return } line = strings.TrimSpace(line) lineCount++ if line == "" { fmt.Println() continue } days := strings.Fields(line) daysLen := len(days) if (len(days) != 7) { fmt.Println("There aren't 7 days in line", lineCount) return } if len(distinctStrings(days)) != 7 { // implies some days have the same name fmt.Println(" ∞ ", line) continue } for abbrevLen := 1; ; abbrevLen++ { abbrevs := make([]string, daysLen) for i := 0; i < daysLen; i++ { abbrevs[i] = takeRunes(days[i], abbrevLen) } if len(distinctStrings(abbrevs)) == 7 { fmt.Printf("%2d %s\n", abbrevLen, line) break } } }
}</lang>
- Output:
Same as Kotlin entry.
Haskell
<lang haskell>import Data.List (inits, intercalate, nub, transpose)
-- ABBREVIATIONS ------------------------------------------------------------- abbrevns :: [String] -> [String] abbrevns xs =
let n = length xs in case n of 0 -> [] _ -> head $ dropWhile ((< n) . length) $ nub <$> transpose (inits <$> xs)
-- REPORT -------------------------------------------------------------------- main :: IO () main = do
s <- readFile "./weekDayNames.txt" mapM_ putStrLn $ take 10 $ (intercalate "\t" . (((:) . show . length . head . abbrevns . words) <*> return)) <$> lines s</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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
Java
<lang Java>import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map;
public class Abbreviations {
public static void main(String[] args) throws IOException { Path path = Paths.get("days_of_week.txt"); List<String> readAllLines = Files.readAllLines(path); for (int i = 0; i < readAllLines.size(); i++) { String line = readAllLines.get(i); if (line.length() == 0) continue;
String[] days = line.split(" "); if (days.length != 7) throw new RuntimeException("There aren't 7 days on line " + (i + 1));
Map<String, Integer> temp = new HashMap<>(); for (String day : days) { Integer count = temp.getOrDefault(day, 0); temp.put(day, count + 1); } if (temp.size() < 7) { System.out.print(" ∞ "); System.out.println(line); continue; }
int len = 1; while (true) { temp.clear(); for (String day : days) { String sd; if (len >= day.length()) { sd = day; } else { sd = day.substring(0, len); } Integer count = temp.getOrDefault(sd, 0); temp.put(sd, count + 1); } if (temp.size() == 7) { System.out.printf("%2d %s\n", len, line); break; } len++; } } }
}</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Kotlin
<lang scala>// version 1.1.4-3
import java.io.File
val r = Regex("[ ]+")
fun main(args: Array<String>) {
val lines = File("days_of_week.txt").readLines() for ((i, line) in lines.withIndex()) { if (line.trim().isEmpty()) { println() continue } val days = line.trim().split(r) if (days.size != 7) throw RuntimeException("There aren't 7 days in line ${i + 1}") if (days.distinct().size < 7) { // implies some days have the same name println(" ∞ $line") continue } var len = 1 while (true) { if (days.map { it.take(len) }.distinct().size == 7) { println("${"%2d".format(len)} $line") break } len++ } }
}</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Objeck
<lang objeck>use System.IO.File; use Collection;
class Abbreviations {
function : Main(args : String[]) ~ Nil { if(args->Size() = 1) { Go(args[0]); }; }
function : Go(file : String) ~ Nil { reader := FileReader->New(file); leaving { reader->Close(); }; cache := StringMap->New(); line := reader->ReadString(); while(line <> Nil) { if(line->Size() > 0) { days := line->Split(" ");
cache->Empty(); each(i : days) { day := days[i]; cache->Insert(day, IntHolder->New(1)); };
if(cache->Size() < 7) { " ∞ {$line}"->PrintLine(); };
len := 1; while(true) { cache->Empty(); each(i : days) { day := days[i]; sd : String; if(len >= day->Size()) { sd := day; } else { sd := day->SubString(len); };
count := cache->Find(sd)->As(IntHolder); if(count = Nil) { cache->Insert(sd, IntHolder->New(1)); } else { count->Inc(); }; };
if(cache->Size() = 7) { "{$len} {$line}"->PrintLine(); break; }; len += 1; }; };
line := reader->ReadString(); }; }
}</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Perl
Output is the same as for Perl 6.
<lang perl>use utf8; binmode STDOUT, ":utf8";
sub auto_abbreviate {
my($string) = @_; my @words = split ' ', $string; return unless @words; map { $max = length($_) if length($_) > $max } @words; for $i (1..$max-1) { my %seen; return $i if @words == grep {!$seen{substr($_,0,$i)}++} @words; } return '∞';
}
open $fh, '<:encoding(UTF-8)', 'DoWAKA.txt'; while ($_ = <$fh>) {
print "$.) " . auto_abbreviate($_) . ' ' . $_;
}</lang>
Perl 6
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 is 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.
Note that this is using a previous version of the date file that has erroneous duplicate day names (see line 90). Since the effort was already expended to catch such problems, it may as well be demonstrated.
<lang perl6>sub auto-abbreviate ( Str $string ) {
return Nil unless my @words = $string.words; return $_ if @words».substr(0, $_).Set == @words for 1 .. @words».chars.max; return '∞';
}
- Testing
say ++$, ') ', .&auto-abbreviate, ' ', $_ for './DoWAKA.txt'.IO.lines;</lang>
- Output:
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 6) 4 Guiragui Yergou_shapti Yerek_shapti Tchorek_shapti Hink_shapti Ourpat Shapat 7) 2 domingu llunes martes miércoles xueves vienres sábadu 8) 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 9) 6 Igande Astelehen Astearte Asteazken Ostegun Ostiral Larunbat 10) 4 Robi_bar Shom_bar Mongal_bar Budhh_bar BRihashpati_bar Shukro_bar Shoni_bar 11) 2 Nedjelja Ponedeljak Utorak Srijeda Cxetvrtak Petak Subota 12) 5 Disul Dilun Dimeurzh Dimerc'her Diriaou Digwener Disadorn 13) 2 nedelia ponedelnik vtornik sriada chetvartak petak sabota 14) 13 sing_kei_yath sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 15) 4 Diumenge Dilluns Dimarts Dimecres Dijous Divendres Dissabte 16) 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-ahzee 17) 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 18) 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 19) 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 20) 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 21) 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 22) 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 23) 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 24) 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 25) 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 26) Nil 27) 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 28) 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 29) 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 30) 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 31) 2 dimanche lundi mardi mercredi jeudi vendredi samedi 32) 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 33) 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 34) 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 35) 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 36) 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 37) 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 38) 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 39) 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 40) 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 41) 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 42) 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 43) 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 44) 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 45) 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 46) 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 47) 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 48) 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 49) 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 50) 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 51) 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 52) 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 53) 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 54) 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 55) 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 56) 3 Jabot Manre Juje Wonje Taije Balaire Jarere 57) 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 58) 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 59) 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 60) 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 61) 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 62) 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 63) 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 64) 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 65) 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 66) 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 67) 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 68) 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 69) 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 70) 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 71) 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 72) 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 73) 2 domingo lunes martes miércoles jueves viernes sábado 74) 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 75) 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 76) 2 söndag måndag tisdag onsdag torsdag fredag lordag 77) 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 78) 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 79) 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 80) 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 81) 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 82) 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 83) 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 84) 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 85) 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 86) 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 87) 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 88) 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 89) 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 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
Python
Imperative
<lang python>def shortest_abbreviation_length(line, list_size):
words = line.split() word_count = len(words) # Can't give true answer with unexpected number of entries if word_count != list_size: raise ValueError(f'Not enough entries, expected {list_size} found {word_count}')
# Find the small slice length that gives list_size unique values abbreviation_length = 1 abbreviations = set() while(True): abbreviations = {word[:abbreviation_length] for word in words} if len(abbreviations) == list_size: return abbreviation_length abbreviation_length += 1 abbreviations.clear()
def automatic_abbreviations(filename, words_per_line):
with open(filename) as file: for line in file: line = line.rstrip() if len(line) > 0: length = shortest_abbreviation_length(line, words_per_line) print(f'{length:2} {line}') else: print()
automatic_abbreviations('daysOfWeek.txt', 7)</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Functional
<lang python>import itertools
- abbrevLen :: [String] -> Int
def abbrevLen(xs):
n = len(xs) return next( len(a[0]) for a in map( lambda x: nub(map(lambda y: .join(y), x)), transpose(map(inits, xs)) ) if n == len(a) )
- TEST ----------------------------------------------------
def main():
xs = list(map(strip, lines( readFile('weekDayNames.txt') ))) for i, n in enumerate(map(compose(abbrevLen)(words), xs)): print (n, ' ', xs[i])
- GENERIC -------------------------------------------------
- compose (<<<) :: (b -> c) -> (a -> b) -> a -> c
def compose(g):
return lambda f: lambda x: g(f(x))
- inits :: [a] -> a
def inits(xs):
return scanl(lambda a, x: a + [x])( [] )(list(xs))
- lines :: String -> [String]
def lines(s):
return s.splitlines()
- nub :: [a] -> [a]
def nub(xs):
return list(dict.fromkeys(xs))
- readFile :: FilePath -> IO String
def readFile(fp):
return open(fp).read()
- scanl is like reduce, but returns a succession of
- intermediate values, building from the left.
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
def scanl(f):
return lambda a: lambda xs: ( list(itertools.accumulate([a] + list(xs), f)) )
- strip :: String -> String
def strip(s):
return s.strip()
def transpose(xs):
return list(map(list, zip(*xs)))
- words :: String -> [String]
def words(s):
return s.split()
- MAIN ---
if __name__ == '__main__':
main()</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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
REXX
<lang rexx>/*REXX program finds the minimum length abbreviation for a lists of words (from a file).*/ parse arg uw /*obtain optional arguments from the CL*/ iFID= 'ABBREV_A.TAB' /*name of the file that has the table. */ say 'minimum' /*display the first part of the title. */ say 'abbrev' center("days of the week", 80) /*display the title for the output. */ say '══════' center("", 80, '═') /*display separator for the title line.*/
/* [↓] process the file until done. */ do while lines(iFID)\==0; days=linein(iFID) /*read a line (should contain 7 words).*/ minLen= abb(days) /*find the minimum abbreviation length.*/ say right(minLen, 4) ' ' days /*display a somewhat formatted output. */ end /*j*/
exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ abb: procedure; parse arg x; #=words(x) /*obtain list of words; find how many.*/
if #==0 then return /*check for a blank line or null line. */ @.= /*@. is a stemmed array of the words.*/ L=0 /*L is the max length of " " */ do j=1 for #; @.j=word(x, j) /*assign to array for faster processing*/ L.j=length(@.j); L= max(L, L.j) /*find the maximum length of any item. */ end /*L*/ /* [↓] determine minimum abbrev length*/ do m=1 for L; $= /*for all lengths, find a unique abbrev*/ do k=1 to #; a=left(@.k, m) /*get an abbreviation (with length M).*/ if wordpos(a,$)\==0 then iterate M /*test this abbreviation for uniquness.*/ $=$ a /*so far, it's unique; add to the list.*/ end /*k*/ leave m /*a good abbreviation length was found.*/ end /*m*/ return m</lang>
- output when using the default input file containing the complete list of words:
minimum abbrev days of the week ══════ ════════════════════════════════════════════════════════════════════════════════ 2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 4 Diumenge Dilluns Dimarts Dimecres Dijous Divendres Dissabte 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ╞riδjudagur Miδvikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sφndag mandag tirsdag onsdag torsdag fredag lφrdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 1 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Tcl
<lang tcl> set f [open abbreviations_automatic_weekdays.txt] set lines [split [read -nonewline $f] \n] close $f
foreach days $lines {
if {[string length $days] == 0} continue if {[llength $days] != 7} { throw ERROR {not 7 days in a line} } if {[llength [lsort -unique $days]] != 7} { throw ERROR {not all 7 days in a line are distinct} } for {set i 0} {1} {incr i} { if {[llength [lsort -unique [lmap x $days {string range $x 0 $i}]]] == 7} break } incr i puts "$i $days"
} </lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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
VBA
Function : <lang vb>Function MinimalLenght(strLine As String) As Integer Dim myVar As Variant, I As Integer, Flag As Boolean, myColl As Collection, Count As Integer
myVar = Split(strLine, " ") Count = 0 Do Set myColl = New Collection Count = Count + 1 On Error Resume Next Do myColl.Add Left$(myVar(I), Count), Left$(myVar(I), Count) I = I + 1 Loop While Err.Number = 0 And I <= UBound(myVar) Flag = Err.Number = 0 On Error GoTo 0 I = 0 Set myColl = Nothing Loop While Not Flag MinimalLenght = Count
End Function</lang> To call it : <lang vb>Sub Main_Abbr_Auto() Dim Nb As Integer, s As String, Result() As String, c As Integer
Nb = FreeFile Open "C:\Users\" & Environ("Username") & "\Desktop\Abbreviations_Auto.txt" For Input As #Nb While Not EOF(Nb) Line Input #Nb, s If InStr(s, "þ") > 0 Then s = Right(s, Len(s) - 2) If s <> vbNullString Then ReDim Preserve Result(c) Result(c) = Left$(MinimalLenght(s) & " ", 4) & s Debug.Print Result(c) c = c + 1 End If Wend Close #Nb
End Sub</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 12 sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 6 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat 2 Sunnudagur Mánudagur ^%ri´�judagur Mi´�vikudagar Fimmtudagur FÖstudagur Laugardagur 2 sundio lundio mardio merkurdio jovdio venerdio saturdio 3 Minggu Senin Selasa Rabu Kamis Jumat Sabtu 2 Dominica Lunedi Martedi Mercuridi Jovedi Venerdi Sabbato 4 Dé_Domhnaigh Dé_Luain Dé_Máirt Dé_Ceadaoin Dé_ardaoin Dé_hAoine Dé_Sathairn 2 domenica lunedí martedí mercoledí giovedí venerdí sabato 2 Nichiyou_bi Getzuyou_bi Kayou_bi Suiyou_bi Mokuyou_bi Kin'you_bi Doyou_bi 1 Il-yo-il Wol-yo-il Hwa-yo-il Su-yo-il Mok-yo-il Kum-yo-il To-yo-il 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 3 sve-tdien pirmdien otrdien tresvdien ceturtdien piektdien sestdien 2 Sekmadienis Pirmadienis Antradienis Trec^iadienis Ketvirtadienis Penktadienis S^es^tadienis 3 Wangu Kazooba Walumbe Mukasa Kiwanuka Nnagawonye Wamunyi 12 xing-_qi-_rì xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 3 Jedoonee Jelune Jemayrt Jecrean Jardaim Jeheiney Jesam 3 Jabot Manre Juje Wonje Taije Balaire Jarere 5 geminrongo minòmishi mártes mièrkoles misheushi bèrnashi mishábaro 2 Ahad Isnin Selasa Rabu Khamis Jumaat Sabtu 2 sÆ�ndag mandag tirsdag onsdag torsdag fredag lÆ�rdag 7 lo_dimenge lo_diluns lo_dimarç lo_dimèrcres lo_dijòus lo_divendres lo_dissabte 4 djadomingo djaluna djamars djarason djaweps djabièrna djasabra 2 Niedziela Poniedzial/ek Wtorek S,roda Czwartek Pia,tek Sobota 3 Domingo segunda-feire terça-feire quarta-feire quinta-feire sexta-feira såbado 2 Domingo Lunes martes Miercoles Jueves Viernes Sabado 2 Duminicª Luni Mart'i Miercuri Joi Vineri Sâmbªtª 2 voskresenie ponedelnik vtornik sreda chetverg pyatnitsa subbota 4 Sunday Di-luain Di-màirt Di-ciadain Di-ardaoin Di-haoine Di-sathurne 2 nedjelja ponedjeljak utorak sreda cxetvrtak petak subota 5 Sontaha Mmantaha Labobedi Laboraro Labone Labohlano Moqebelo 2 Iridha- Sandhudha- Anga.haruwa-dha- Badha-dha- Brahaspa.thindha- Sikura-dha- Sena.sura-dha- 2 nedel^a pondelok utorok streda s^tvrtok piatok sobota 2 Nedelja Ponedeljek Torek Sreda Cxetrtek Petek Sobota 2 domingo lunes martes miércoles jueves viernes sábado 2 sonde mundey tude-wroko dride-wroko fode-wroko freyda Saturday 7 Jumapili Jumatatu Jumanne Jumatano Alhamisi Ijumaa Jumamosi 2 söndag måndag tisdag onsdag torsdag fredag lordag 2 Linggo Lunes Martes Miyerkoles Huwebes Biyernes Sabado 6 Lé-pài-jít Pài-it Pài-jï Pài-sañ Pài-sì Pài-gÖ. Pài-lák 7 wan-ar-tit wan-tjan wan-ang-kaan wan-phoet wan-pha-ru-hat-sa-boh-die wan-sook wan-sao 5 Tshipi Mosupologo Labobedi Laboraro Labone Labotlhano Matlhatso 6 Pazar Pazartesi Sali Çar,samba Per,sembe Cuma Cumartesi 2 nedilya ponedilok vivtorok sereda chetver pyatnytsya subota 8 Chu?_Nhâ.t Thú*_Hai Thú*_Ba Thú*_Tu* Thú*_Na'm Thú*_Sáu Thú*_Ba?y 6 dydd_Sul dyds_Llun dydd_Mawrth dyds_Mercher dydd_Iau dydd_Gwener dyds_Sadwrn 3 Dibeer Altine Talaata Allarba Al_xebes Aljuma Gaaw 7 iCawa uMvulo uLwesibini uLwesithathu uLuwesine uLwesihlanu uMgqibelo 2 zuntik montik dinstik mitvokh donershtik fraytik shabes 7 iSonto uMsombuluko uLwesibili uLwesithathu uLwesine uLwesihlanu uMgqibelo 7 Dies_Dominica Dies_Lunæ Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Saturni 11 Bazar_gÜnÜ Bazar_ærtæsi Çærs,ænbæ_axs,amò Çærs,ænbæ_gÜnÜ CÜmæ_axs,amò CÜmæ_gÜnÜ CÜmæ_Senbæ 2 Sun Moon Mars Mercury Jove Venus Saturn 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 KoseEraa GyoOraa BenEraa Kuoraa YOwaaraa FeEraa Memenaa 5 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Sonnabend 1 Domingo Luns Terza_feira Corta_feira Xoves Venres Sábado 7 Dies_Solis Dies_Lunae Dies_Martis Dies_Mercurii Dies_Iovis Dies_Veneris Dies_Sabbatum 12 xing-_qi-_tiàn xing-_qi-_yi-. xing-_qi-_èr xing-_qi-_san-. xing-_qi-_sì xing-_qi-_wuv. xing-_qi-_liù 4 djadomingu djaluna djamars djarason djaweps djabièrnè djasabra 2 Killachau Atichau Quoyllurchau Illapachau Chaskachau Kuychichau Intichau
Yabasic
<lang Yabasic> a = open("days_of_week.txt", "r")
while(not eof(#a))
line input #a s$ print buscar(s$), " ", s$
wend
close #a
sub buscar(s$)
local n, d, i, j, s, a$, b$, r$(1) n = token(s$, r$()) d = 1 repeat s = true for i = 1 to n for j = i + 1 to n a$ = left$(r$(i), d) b$ = left$(r$(j), d) if a$ = "" or b$ = "" s = true : break 2 if a$ = b$ s = false : d = d + 1 : break 2 next next until(s) return d
end sub</lang>
zkl
zkl doesn't grok UTF-8 so I'm using a byte by byte check. It works surprisingly well. <lang zkl>nds:=File("daysOfWeek.txt").read().howza(11) // stripped lines .pump(List,Void.Filter,fcn(day){
d,N,m := day.split(),d.len(),(0).max(d.apply("len")); // N==7 foreach n in ([1..m]){ ds:=d.apply("get",0,n); // ("Su","Mo","Tu","We","Th","Fr","Sa") foreach a,b in (N,[a+1..N-1]){ if(ds[a]==ds[b]) continue(3); } # Th==Fr? return(n,day); // part way though the words and found unique } return(m,day); // no match nowhere
}); foreach n,s in (nds){ println("%3d %s".fmt(n,s)); }</lang>
- Output:
2 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 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ë 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 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 13 sing_kei_yath sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk 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-ahzee 6 dy_Sul dy_Lun dy_Meurth dy_Mergher dy_You dy_Gwener dy_Sadorn 2 Dimanch Lendi Madi Mèkredi Jedi Vandredi Samdi 2 nedjelja ponedjeljak utorak srijeda cxetvrtak petak subota 2 nede^le ponde^lí úterÿ str^eda c^tvrtek pátek sobota 2 Sondee Mondee Tiisiday Walansedee TOOsedee Feraadee Satadee 2 s0ndag mandag tirsdag onsdag torsdag fredag l0rdag 2 zondag maandag dinsdag woensdag donderdag vrijdag zaterdag 2 Diman^co Lundo Mardo Merkredo ^Jaùdo Vendredo Sabato 1 pÜhapäev esmaspäev teisipäev kolmapäev neljapäev reede laupäev 7 Diu_prima Diu_sequima Diu_tritima Diu_quartima Diu_quintima Diu_sextima Diu_sabbata 2 sunnudagur mánadagur tÿsdaguy mikudagur hósdagur friggjadagur leygardagur 2 Yek_Sham'beh Do_Sham'beh Seh_Sham'beh Cha'har_Sham'beh Panj_Sham'beh Jom'eh Sham'beh 2 sunnuntai maanantai tiistai keskiviiko torsktai perjantai lauantai 2 dimanche lundi mardi mercredi jeudi vendredi samedi 4 Snein Moandei Tiisdei Woansdei Tonersdei Freed Sneon 2 Domingo Segunda_feira Martes Mércores Joves Venres Sábado 2 k'vira orshabati samshabati otkhshabati khutshabati p'arask'evi shabati 2 Sonntag Montag Dienstag Mittwoch Donnerstag Freitag Samstag 2 Kiriaki' Defte'ra Tri'ti Teta'rti Pe'mpti Paraskebi' Sa'bato 3 ravivaar somvaar mangalvaar budhvaar guruvaar shukravaar shanivaar 7 pópule pó`akahi pó`alua pó`akolu pó`ahá pó`alima pó`aono 7 Yom_rishon Yom_sheni Yom_shlishi Yom_revi'i Yom_chamishi Yom_shishi Shabat 3 ravivara somavar mangalavar budhavara brahaspativar shukravara shanivar 3 vasárnap hétfö kedd szerda csütörtök péntek szombat