Amb
Define and give an example of the Amb operator.
Amb
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
The Amb operator takes some number of expressions (or values if that's simpler in the language) and nondeterministically yeilds the one or fails if given no parameter, amb returns the value that doesn't lead to failure.
The example is using amb to choose four words from the following strings: set 1: "the" "that" "a" set 2: "frog" "elephant" "thing" set 3: "walked" "treaded" "grows" set 4: "slowly" "quickly"
it is a failure if the last character of word 1 is not equal to the first character of word 2, and similarly with word 2 and word 3, as well as word 3 and word 4. (the only successful sentence is "that thing grows slowly").