Abbreviations, automatic: Difference between revisions

(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
Line 4,113:
6: Igande,Astele,Astear,Asteaz,Ostegu,Ostira,Larunb
4: Robi,Shom,Mong,Budh,BRih,Shuk,Shon</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Also works with gojq, the Go implementation of jq, and with fq.'''
 
'''Adapted from [[#Wren|Wren]]'''
<syntaxhighlight lang=jq>
def trim: sub("^ *";"") | sub(" $";"");
 
# Each item in the stream should be a string with $n names
def minimum_abbreviation_lengths(stream; $n):
foreach (stream|trim) as $line ({i: 0};
.i+=1
| if $line == "" then .emit = ""
else [$line|splits(" *")] as $days
| if ($days|length != $n) then .emit = "WARNING: line \(.i) does not have \($n) tokens"
elif ($days|unique|length < $n) # some days have the same name
then .emit = "∞: \($line)"
else .len = 1
| .emit = false
| until(.emit;
.len as $len
| if ($days|map(.[:$len])|unique|length == $n)
then .emit = "\($len): \($line)"
else .len += 1
end)
end
end;
.emit) ;
 
minimum_abbreviation_lengths(inputs; 7)
</syntaxhighlight>
''Invocation:'' jq -nrR -f abbreviations-automatic.jq
days_of_week.txt
{{output}}
Semantically identical to that at [[#Wren|Wren]].
 
=={{header|Julia}}==
2,503

edits