Packing Squares into A Rectangle, Using Constraints (CLINGO)
<p>Use CLINGO to pack a given set of squares into a given rectangular area without overlaps.
 For example, we want to pack the squares:</p>

<p>A of size 4, B of size 3, C &amp; D of size 2, E of size 1</p>

<p>into an area 5 x 8. </p>

<pre><code> #const x = 8.
  #const y = 5.

square(a,4; b,3; c,2; d,2; e,1).

%generate a grid:
1 { pos(X,Y) } 1 :- x(X), y(Y).

%generate placement of the squares
1 { placement(P, SQ) } 1 :- square(SQ), pos(P).

%throw out overlaps
</code></pre>

<p>I'm not sure what the constraint to throwing out overlapping squares would be, or if I'm doing this right.</p>