Alternade words: Difference between revisions

m (→‎{{header|FutureBasic}}: search on background thread)
(→‎OCaml: add)
Line 2,186:
57: throaty → tray hot
58: calliope → clip aloe</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">module StrSet = Set.Make(String)
 
let seq_lines ch =
let rec repeat () =
match input_line ch with
| s -> Seq.Cons (s, repeat)
| exception End_of_file -> Nil
in repeat
 
let min_len l s =
l <= String.length s
 
let get_alternade set s =
let s0 = String.init (succ (String.length s) lsr 1) (fun i -> s.[i + i])
and s1 = String.init (String.length s lsr 1) (fun i -> s.[i + succ i]) in
if StrSet.mem s0 set && StrSet.mem s1 set
then Some (Printf.sprintf "%s | %s %s" s s0 s1) else None
 
let () =
let set = seq_lines stdin |> Seq.filter (min_len 3) |> StrSet.of_seq in
StrSet.to_seq set |> Seq.filter (min_len 6)
|> Seq.filter_map (get_alternade set) |> Seq.iter print_endline</syntaxhighlight>
{{out}}
<pre style="max-height:20em">
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|Perl}}==
559

edits