Word ladder: Difference between revisions

139 bytes removed ,  2 years ago
Promote to full task
m (added related tasks.)
(Promote to full task)
Line 1:
{{Draft taskTask}}
Yet another shortest path problem. Given two words of equal length the task is to transpose the first into the second.
 
Line 140:
<lang fsharp>
// Word ladder: Nigel Galloway. June 5th., 2021
let fG n g=n|>List.partition(fun n->2>Seq.fold2(fun z n g->z+if n=g then 0 else 1) 0 n g)
open System.Text.RegularExpressions
let fN g=List.init(String.length g)(fun n->let g=g.ToCharArray() in g.[n]<-'.'; g|>System.String)|>String.concat "|"
let fG n g=let g=fN g in n|>List.partition(fun n->Regex.IsMatch(n,g))
let wL n g=let dict=seq{use n=System.IO.File.OpenText("unixdict.txt") in while not n.EndOfStream do yield n.ReadLine()}|>Seq.filter(Seq.length>>(=)(Seq.length n))|>List.ofSeq|>List.except [n]
let (|Done|_|) n=n|>List.tryFind((=)g)
2,172

edits