Alternade words: Difference between revisions

(→‎{{header|Ruby}}: Added Ruby)
Line 2,539:
</pre>
 
=={{header|Ruby}}==
<lang ruby>words = File.open("unixdict.txt").map(&:chomp)
 
res = words.filter_map do |word|
next if word.size < 6
splitted = word.each_char.partition.with_index{|_,i| i.even? }.map(&:join)
next unless splitted.all?{|split| words.bsearch{|w| w >= split } == split}
"#{word}: #{splitted.join(", ")}"
end
 
puts res
</lang>
{{out}}
<pre style="height: 30ex">accost: acs, cot
accuse: acs, cue
afield: ail, fed
agleam: ala, gem
alcott: act, lot
allele: all, lee
allied: ale, lid
alpert: apr, let
ambient: abet, min
annette: ante, net
apport: apr, pot
ariadne: aide, ran
assist: ass, sit
battle: btl, ate
blaine: ban, lie
brenda: bed, rna
calliope: clip, aloe
choose: cos, hoe
choosy: cos, hoy
claire: car, lie
collude: clue, old
effete: eft, fee
fabric: fbi, arc
fealty: fat, ely
fluent: fun, let
forwent: fret, own
friend: fin, red
george: gog, ere
inroad: ira, nod
israel: ire, sal
jaunty: jut, any
joanne: jan, one
lounge: lug, one
oriole: oil, roe
oswald: owl, sad
parrot: pro, art
peoria: poi, era
pierre: per, ire
poodle: pol, ode
pounce: puc, one
racial: rca, ail
realty: rat, ely
sordid: sri, odd
spatial: sail, pta
sprain: sri, pan
strain: sri, tan
strait: sri, tat
sturdy: sud, try
sweaty: set, way
tattle: ttl, ate
theorem: term, hoe
though: tog, huh
throaty: tray, hot
triode: tid, roe
triune: tin, rue
troupe: top, rue
truant: tun, rat
twirly: til, wry
</pre>
=={{header|Rust}}==
<lang rust>use std::collections::BTreeSet;
1,149

edits