Best shuffle: Difference between revisions

Content added Content deleted
m (→‎{{header|Picat}}: Added subsection, added {{out}})
Line 3,022: Line 3,022:
Using a CP (Constraint Programming) solver guarantees an optimal solution. This is deterministic since the solve heuristic ("split") always give the same first result.
Using a CP (Constraint Programming) solver guarantees an optimal solution. This is deterministic since the solve heuristic ("split") always give the same first result.


<lang Picat>go =>
<lang Picat>import cp.

go =>
Words = ["abracadabra",
Words = ["abracadabra",
"seesaw",
"seesaw",
Line 3,085: Line 3,087:
end.</lang>
end.</lang>


{{out}}
Output:
<pre>abracadabra, baabacadrar, (0)
<pre>abracadabra, baabacadrar, (0)
seesaw, assewe, (0)
seesaw, assewe, (0)
Line 3,095: Line 3,097:
aaaaaaa, aaaaaaa, (7)</pre>
aaaaaaa, aaaaaaa, (7)</pre>


===All optimal solutions===

Using a constraint solver makes it quite easy to generate all optimal solutions.
Using a constraint solver makes it quite easy to generate all optimal solutions.
<lang Picat>go2 ?=>
<lang Picat>go2 ?=>
Line 3,126: Line 3,128:
go2 => true.</lang>
go2 => true.</lang>


{{out}}
Output:
<pre>word = abracadabra
<pre>word = abracadabra
best_score = 0
best_score = 0
Line 3,169: Line 3,171:
num_solutions = 1
num_solutions = 1
solutions = [aaaaaaa]</pre>
solutions = [aaaaaaa]</pre>



=={{header|PicoLisp}}==
=={{header|PicoLisp}}==