Changeable words: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: used more idiomatic code.)
Line 710: Line 710:


=={{header|Julia}}==
=={{header|Julia}}==
See [[Alternade_words#Julia] for the foreachword function.
After finding for example "are <=> art", we do not also list the redundant "art <=> are" below.
<lang julia>function changeable(wordfile, lengthover)
<lang julia>const alts = Set{String}()
function ischangeable(w, d)
words, results = split(read(wordfile, String)), []
alternatives = [w[1:p[1]-1] * p[2] * w[p[1]+1:end] for p in Iterators.product(1:length(w), 'a':'z')]
worddict = Dict(w => length(w) for w in words)
for w in words
for a in alternatives
len = get(worddict, w, 0)
if a != w && haskey(d, a)
if len <= lengthover
result = join(sort([w, a]), " <=> ")
continue
if !(result in alts)
end
push!(alts, result)
return result
alternatives = [w[1:p[1]-1] * p[2] * w[p[1]+1:end] for p in Iterators.product(1:len, 'a':'z')]
for a in alternatives
if a != w && haskey(worddict, a)
push!(results, join(sort([w, a]), " <=> "))
break
end
end
end
end
end
end
return ""
println(join(sort(unique(results)), "\n"))
end
end


changeable("unixdict.txt", 11)
foreachword("unixdict.txt", ischangeable, minlen = 12, colwidth=40, numcols=2)
</lang>{{out}}
</lang>{{out}}
<pre>
<pre>
Word source: unixdict.txt
aristotelean <=> aristotelian

claustrophobia <=> claustrophobic
aristotelean <=> aristotelian claustrophobia <=> claustrophobic
committeeman <=> committeemen
committeewoman <=> committeewomen
committeeman <=> committeemen committeewoman <=> committeewomen
complementary <=> complimentary
complementary <=> complimentary confirmation <=> conformation
congresswoman <=> congresswomen councilwoman <=> councilwomen
confirmation <=> conformation
craftsperson <=> draftsperson eavesdropped <=> eavesdropper
congresswoman <=> congresswomen
frontiersman <=> frontiersmen handicraftsman <=> handicraftsmen
councilwoman <=> councilwomen
incommutable <=> incomputable installation <=> instillation
craftsperson <=> draftsperson
kaleidescope <=> kaleidoscope neuroanatomy <=> neuroanotomy
eavesdropped <=> eavesdropper
newspaperman <=> newspapermen nonagenarian <=> nonogenarian
frontiersman <=> frontiersmen
onomatopoeia <=> onomatopoeic philanthrope <=> philanthropy
handicraftsman <=> handicraftsmen
prescription <=> proscription schizophrenia <=> schizophrenic
incommutable <=> incomputable
shakespearean <=> shakespearian spectroscope <=> spectroscopy
installation <=> instillation
underclassman <=> underclassmen upperclassman <=> upperclassmen
kaleidescope <=> kaleidoscope
neuroanatomy <=> neuroanotomy
newspaperman <=> newspapermen
nonagenarian <=> nonogenarian
onomatopoeia <=> onomatopoeic
philanthrope <=> philanthropy
prescription <=> proscription
schizophrenia <=> schizophrenic
shakespearean <=> shakespearian
spectroscope <=> spectroscopy
underclassman <=> underclassmen
upperclassman <=> upperclassmen
</pre>
</pre>