Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I post a solution showing a possible Prolog coding, in style <em>generate and test</em>. There is some slot where you'll place appropriate arithmetic, just to complete your assignment.</p> <pre><code>%% placing place_squares(Big, Small, Squares) :- place_not_overlapping(Big, Small, [], Squares). place_not_overlapping(Big, Small, SoFar, Squares) :- available_position(Big, Small, Position), \+ overlapping(Small, Position, SoFar), place_not_overlapping(Big, Small, [Position|SoFar], Squares). place_not_overlapping(_Big, _Small, Squares, Sorted) :- sort(Squares, Sorted). overlapping(Size, R*C, Squares) :- member(X*Y, Squares), ... % write conditions here available_position(Big, Small, Row*Col) :- Range is Big - Small + 1, between(1, Range, Row), between(1, Range, Col). </code></pre> <p>after placing, it's easy to display</p> <pre><code>%% drawing draw_squares(Big, Small, Squares) :- forall(between(1, Big, Row), (forall(between(1, Big, Col), draw_point(Row*Col, Small, Squares)), nl )). draw_point(Point, Small, Squares) :- ( nth1(I, Squares, Square), contained(Point, Square, Small) ) -&gt; write(I) ; write('-'). contained(R*C, A*B, Size) :- ... % place arithmetic here </code></pre> <p>the result with requested dimensions, and drawing</p> <pre><code>?- place_squares(5,2,Q),draw_squares(5,2,Q). 1122- 1122- 3344- 3344- ----- Q = [1*1, 1*3, 3*1, 3*3] ; 1122- 1122- 33-44 33-44 ----- Q = [1*1, 1*3, 3*1, 3*4] ; 1122- 1122- 33--- 3344- --44- Q = [1*1, 1*3, 3*1, 4*3] . ... </code></pre> <p>the place_squares/3 output is sorted, to ease displaying, and could as well be used to get rid of symmetry, and get a count of all solutions:</p> <pre><code>9 ?- setof(Q, place_squares(5,2,Q), L), length(L, N). L = [[], [1*1], [1*1, 1*3], [1*1, 1*3, 3*1], [1*1, 1*3, 3*1, ... * ...], [1*1, 1*3, ... * ...|...], [1*1, ... * ...|...], [... * ...|...], [...|...]|...], N = 314. </code></pre> <p>You can note that this accepts boards with 'spare' space. You could filter out such incomplete solutions, to complete your task.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload