Isograms and heterograms: Difference between revisions

Content added Content deleted
m (→‎{{header|Raku}}: concurrency)
(julia example)
Line 135: Line 135:
valedictory
valedictory
voluntarism
voluntarism
</pre>

=={{header\Julia}}==
<lang ruby>function isogram(word)
wchars, uchars = collect(word), unique(collect(word))
ulen, wlen = length(uchars), length(wchars)
(wlen == 1 || ulen == wlen) && return 1
n = count(==(first(uchars)), wchars)
return all(i -> count(==(uchars[i]), wchars) == n, 2:ulen) ? n : 0
end

words = split(lowercase(read("documents/julia/unixdict.txt", String)), r"\s+")
orderlengthtuples = [(isogram(w), length(w), w) for w in words]

tcomp(x, y) = (x[1] != y[1] ? y[1] < x[1] : x[2] != y[2] ? y[2] < x[2] : x[3] < y[3])

nisograms = sort!(filter(t -> t[1] > 1, orderlengthtuples), lt = tcomp)
heterograms = sort!(filter(t -> t[1] == 1 && length(t[3]) > 10, orderlengthtuples), lt = tcomp)

println("N-Isogram N Length\n", "-"^24)
foreach(t -> println(rpad(t[3], 8), lpad(t[1], 5), lpad(t[2], 5)), nisograms)
println("\nHeterogram Length\n", "-"^20)
foreach(t -> println(rpad(t[3], 12), lpad(t[2], 5)), heterograms)
</lang>{{out}}
<pre>
N-Isogram N Length
------------------------
aaa 3 3
iii 3 3
beriberi 2 8
bilabial 2 8
caucasus 2 8
couscous 2 8
teammate 2 8
appall 2 6
emmett 2 6
hannah 2 6
murmur 2 6
tartar 2 6
testes 2 6
anna 2 4
coco 2 4
dada 2 4
deed 2 4
dodo 2 4
gogo 2 4
isis 2 4
juju 2 4
lulu 2 4
mimi 2 4
noon 2 4
otto 2 4
papa 2 4
peep 2 4
poop 2 4
teet 2 4
tete 2 4
toot 2 4
tutu 2 4
ii 2 2

Heterogram Length
--------------------
ambidextrous 12
bluestocking 12
exclusionary 12
incomputable 12
lexicography 12
loudspeaking 12
malnourished 12
atmospheric 11
blameworthy 11
centrifugal 11
christendom 11
consumptive 11
countervail 11
countryside 11
countrywide 11
disturbance 11
documentary 11
earthmoving 11
exculpatory 11
geophysical 11
inscrutable 11
misanthrope 11
problematic 11
selfadjoint 11
stenography 11
sulfonamide 11
switchblade 11
switchboard 11
switzerland 11
thunderclap 11
valedictory 11
voluntarism 11
</pre>
</pre>