Set puzzle: Difference between revisions

→‎{{header|Picat}}: Added subsection
(→‎{{header|Picat}}: Added subsection)
Line 3,160:
 
=={{header|Picat}}==
The problem generator check that it problem has exactly one solution, so that step can take a little time (some seconds). <code>fail/0</code> is used to check for unicity of the solution.
<lang Picat>import util.
import cp.
Line 3,176:
nl.
go => true.
 
 
%
Line 3,188 ⟶ 3,187:
fail, % prove unicity
nl.
 
 
go3 =>
Line 3,196 ⟶ 3,194:
fail, % prove unicity)
nl.
 
 
%
Line 3,223 ⟶ 3,220:
X[I] = Y
end.
 
 
% (Strictly) increasing
Line 3,341 ⟶ 3,337:
 
 
Solving the instance in the task description (<code>go/0</code>):
{{out}}
<pre>[1,[green,one,oval,striped]]
Line 3,360 ⟶ 3,356:
[[purple,one,diamond,open],[purple,two,squiggle,open],[purple,three,oval,open]]</pre>
 
Solving the two random tasks (<code>go2/0</code>) and <code>go3/0</code>):
{{out}::
<pre>[numCards = 9,numWantedSets = 4,setLen = 3]
Line 3,405 ⟶ 3,401:
[[red,diamond,two,striped],[red,oval,one,striped],[red,squiggle,three,striped]]</pre>
 
===Constraint model===
 
Here is the additional code for a '''constraint model'''. Note that the constraint solver only handles integers so the features must be converted to integers. To simplify, the random instance generator does not check for unicity of the problem instance, so it can have (and often have) a lot of solutions.
<lang Picat>go4 =>
Line 3,455 ⟶ 3,451:
 
solve($[ff,split],X).
 
 
%
Line 3,539 ⟶ 3,534:
 
...</pre>
 
 
=={{header|Prolog}}==
495

edits