Amb: Difference between revisions
Content added Content deleted
m (→[[Amb#ALGOL 68]]: fix minor typo.) |
|||
Line 411: | Line 411: | ||
end program;</lang> |
end program;</lang> |
||
We cheat a bit here - this version of ''amb'' must be given the whole list of word sets, and that list is consumed recursively. It can't pick a word from an individual list. |
We cheat a bit here - this version of ''amb'' must be given the whole list of word sets, and that list is consumed recursively. It can't pick a word from an individual list. |
||
=={{header|Tcl}}== |
|||
Brute force, with quick kill of failing attempts: |
|||
<lang Tcl> |
|||
proc amb list {set list} |
|||
proc fit {a b} { |
|||
expr {[string index $a end] eq [string index $b 0]} |
|||
} |
|||
foreach i [amb {the that a}] { |
|||
foreach j [amb {frog elephant thing}] { |
|||
if ![fit $i $j] continue |
|||
foreach k [amb {walked treaded grows}] { |
|||
if ![fit $j $k] continue |
|||
foreach l [amb {slowly quickly}] { |
|||
if [fit $k $l] { |
|||
puts [list $i $j $k $l] |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</lang> |