Odd words: Difference between revisions

no edit summary
m (→‎version 2, caseless: adjusted the record count.)
No edit summary
Line 519:
 
=={{header|Julia}}==
<lang julia>function oddwordsforeachword(wordfile::String, lengthgreatercondition::Function; minlen = 0, colwidth = 15, numcols = 6, toshow = 0)
println("Word source: $wordfile\n")
words = split(read(wordfile, String), r"\s+")
dict, shown = Dict(w => 1 for w in words), 0
for word in words
if (lenoutput = lengthcondition(word, dict)) <!= lengthgreater * 2"" && continue(minlen < 1 || length(word) >= minlen)
subword = mapreduce(i -> word[i],shown *,+= 1:2:len)
haskey(dict, subword) && println print(rpad(wordoutput, 12colwidth), "shown =>% numcols == 0 ? ",\n" subword: "")
toshow > 0 && toshow < shown && break
end
end
end
 
isoddword(w, d) = (o = mapreduce(i -> w[i], *, 1:2:length(w)); haskey(d, o) ? rpad(w, 16) * ": " * o : "")
oddwords("unixdict.txt", 4)
 
foreachword("unixdict.txt", isoddword, minlen=9, numcols=1)
</lang>{{out}}
<pre>
Word source: unixdict.txt
 
barbarian => : brain
childbear => : cider
corrigenda => : cried
gargantuan => : grata
headdress => : hades
palladian => : plain
propionate => : point
salvation => : slain
siltation => : slain
slingshot => : sight
statuette => : saute
supersede => : spree
supervene => : spree
terminable => : trial
</pre>
 
4,102

edits