Data update
This commit is contained in:
parent
81fd053722
commit
52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions
18
Task/Abbreviations-automatic/PHP/abbreviations-automatic.php
Normal file
18
Task/Abbreviations-automatic/PHP/abbreviations-automatic.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function genMinAbbr(array $days): array {
|
||||
$len = 0;
|
||||
while(true) {
|
||||
$dict = [];
|
||||
$len++;
|
||||
foreach($days as $day) {
|
||||
$abbr = substr($day, 0, $len);
|
||||
if (isset($dict[$abbr])) continue 2;
|
||||
$dict[$abbr] = true;
|
||||
}
|
||||
return array_keys($dict);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(explode("\n", file_get_contents("days-of-the-week.txt")) as $line) {
|
||||
if (!$line) { echo "\n"; continue; }
|
||||
echo implode(" ", genMinAbbr(explode(" ", $line))) . "\n";
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
# Experimental!
|
||||
# Find shortest distinct abbreviation length per line
|
||||
# Find shortest distinct abbreviation per line
|
||||
|
||||
Lines ← {"Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
|
||||
"sing_kei_yaht sing_kei_yat sing_kei_yee sing_kei_saam sing_kei_sie sing_kei_ng sing_kei_luk"
|
||||
|
|
@ -7,11 +6,6 @@ Lines ← {"Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
|
|||
"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"}
|
||||
|
||||
# Return 1+max_common_prefix
|
||||
AbbrevLen ← +1/↥◹(/↥↘1)⊞(/+\↧⬚@ =∩°□).
|
||||
Split ← ⊜□⊸(≠@ )
|
||||
RemoveEmpty ← ▽⊸(≡(≠0◇⧻))
|
||||
Line ← ⊂⊂:": " °⋕:⊸(/(⊂⊂) " "≡(⬚@ ↙:°□)⊙¤)⟜AbbrevLen ◇Split
|
||||
≡⍚Line RemoveEmpty Lines
|
||||
≡&p
|
||||
Pref ← +1⬚¯1⊢⊚¬⬚@ ≡≍ # for two strings give pos of first diff char
|
||||
≡◇(&p$"_: _" :/$"_ _"⟜(⧻⊢)≡◇⬚@ ↙/↥/↥⊞◇Pref..Split)▽⊸≡(>0◇⧻)Lines
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue