Odd words: Difference between revisions
Content added Content deleted
m (→version 2, caseless: added a comment.) |
|||
Line 519: | Line 519: | ||
=={{header|Julia}}== |
=={{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) |
|||
⚫ | |||
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 |
|||
⚫ | |||
foreachword("unixdict.txt", isoddword, minlen=9, numcols=1) |
foreachword("unixdict.txt", isoddword, minlen=9, numcols=1) |
||
</lang>{{out}} |
</lang>{{out}} |