Odd words: Difference between revisions

m
m (→‎version 2, caseless: added a comment.)
Line 519:
 
=={{header|Julia}}==
See [[Alternade_words#Julia] for the foreachword function.
<lang julia>function foreachword(wordfile::String, condition::Function; minlen = 0, colwidth = 15, numcols = 6, toshow = 0)
<lang julia>isoddword(w, d) = (o = mapreduce(i -> w[i], *, 1:2:length(w)); haskey(d, o) ? rpad(w, 16) * ": " * o : "")
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 (output = condition(word, dict)) != "" && (minlen < 1 || length(word) >= minlen)
shown += 1
print(rpad(output, colwidth), shown % numcols == 0 ? "\n" : "")
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 : "")
 
foreachword("unixdict.txt", isoddword, minlen=9, numcols=1)
</lang>{{out}}
4,102

edits