Word ladder: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Slightly simpler.)
Line 840: Line 840:
{{trans|Phix}}
{{trans|Phix}}
{{libheader|Wren-sort}}
{{libheader|Wren-sort}}
{{libheader|Wren-seq}}
<lang ecmascript>import "io" for File
<lang ecmascript>import "io" for File
import "/sort" for Find
import "/sort" for Find
import "/seq" for Lst


var words = File.read("unixdict.txt").trim().split("\n")
var words = File.read("unixdict.txt").trim().split("\n")
Line 863: Line 861:
if (Find.first(next, b) != -1) {
if (Find.first(next, b) != -1) {
curr.add(b)
curr.add(b)
System.print(Lst.flatten(curr).join(" -> "))
System.print(curr.join(" -> "))
return
return
}
}
poss = poss.where { |p| !next.contains(p) }.toList
poss = poss.where { |p| !next.contains(p) }.toList
for (i in 0...next.count) {
for (i in 0...next.count) {
var temp = [curr]
var temp = curr.toList
temp.add(next[i])
temp.add(next[i])
todo.add(temp)
todo.add(temp)