begin comment pentomino, 130968;
library A6, A12;
integer solution count, max solution count;
integer piece number, piece count, place count;
integer board length, board width, board area;
integer i, j, k, position;
integer printer, reader;
integer form2id;
integer form3id;

form2id := format({nd});
form3id := format({ndd});

printer := 30;
open(printer);

reader := 20;
open(reader);

max solution count := read(reader);
newline(printer,1);
writetext(printer,{The$first$}); write(printer, form2id, max solution count); writetext(printer,{$solutions:});
newline(printer,3);

board length := read(reader);
board width  := read(reader);
piece count  := read(reader);
place count  := read(reader);
board area   := board length × (board width - 1);

  begin
  integer array board [-39 : 100];
  integer array place, index [1 : piece count];
  integer array information [1 : 8 × place count];
  boolean array unused [1 : piece count];

  procedure print solution;
     begin
     integer i, j;
     writetext(printer,{{c}print$solution:{c}});
     writetext(printer,{{c}board$length$=});
     write(printer, form3id, board length);
     newline(printer,1);
     writetext(printer,{{c}board$width$=});
     write(printer, form3id, board width);
     newline(printer,1);
     writetext(printer,{{c}piece$count$=});
     write(printer, form3id, piece count);
     newline(printer,1);
     writetext(printer,{{c}place$count$=});
     write(printer, form3id, place count);
     newline(printer,1);
     solution count := solution count + 1;

     if solution count > max solution count then
        begin
        writetext(printer,{{c}solution$count$=});
        write(printer, form3id, solution count);
        newline(printer,3);
        goto END OF RUN;
        end 

     newline(printer,1);
     for j := 1 step 1 until 2 × board length do
        begin
        writetext(printer,{-});
        writetext(printer,{$})
        end 
     newline(printer,1);
     for i := 0 step board length until board area do
        begin
        writetext(printer,{I});
        for j := 1 step 1 until board length - 1 do
           begin
           writetext(printer,{$$$});
           if board[i + j] ± board[i + j + 1] then
              writetext(printer,{I})
           else
              writetext(printer,{$})
           end 
        writetext(printer,{$$$});
        writetext(printer,{I});
        newline(printer,1);
        writetext(printer,{$});
        if i < board area then
           begin
              for j := 1 step 1 until board length do
                 begin
                 if board[i + j] ± board[i + j + board length] then
                    begin
                    writetext(printer,{-}); writetext(printer,{$});
                    writetext(printer,{-}); writetext(printer,{$})
                    end
                 else
                    writetext(printer,{$$$$})
                 end
            end
        else
           for j := 1 step 1 until 2 × board length do
              begin
              writetext(printer,{-});
              writetext(printer,{$})
              end 
        newline(printer,1)
        end 
     newline(printer,2);
     end print solution;

   procedure up (field, column); value field, column; integer field, column;
      begin
      integer i, j, k, r, w, piece, count;
      piece number := piece number + 1;
      for piece := 1 step 1 until piece count do
         if unused[piece] then
            begin
            unused[piece] := false 
            board[field] := piece;
            count := place[piece] - 1;
            for i := 0 step 1 until count do
               begin
               w := index[piece] + 4 × i;
               if board[information[w] + field] = 0 then
                  begin
                  if board[information[w + 1] + field] = 0 then
                      begin
                      if board[information[w + 2] + field] = 0 then
                         begin
                         if board[information[w + 3] + field] = 0 then
                            begin
                            for j := 0, 1, 2, 3 do
                                board[information[w + j] + field] := piece;
                            if piece number = piece count then
                              print solution
                            else
                               begin
                               for k := column step 1 until board length do
                                  for r := 0 step board length until board area do
                                     if board[r + k] = 0 then goto NEXT;
                           NEXT:
                               up (r + k, k)
                               end 
                            for j := 0, 1, 2, 3 do
                               board[information[w + j] + field] := 0
                            end
                         end
                     end
                  end
               end 
            unused[piece] := true
            end 
      board[field] := 0;
   DOWN:
      piece number := piece number - 1
      end up;

  position := 1;
  for i := 1 step 1 until piece count do
     begin
     j := read(reader); comment stone piece number, is not used;
     index[i] := position; place[i] := read(reader);
     for j := 1 step 1 until place[i] do
        begin
        for k := 0 step 1 until 3 do
           information[position + k] := read(reader);
        position := position + 4
        end
     end 
  for i := - 39 step 1 until 0, + 61 step 1 until 100 do
     board[i] := - 1;
  for i := 1 step 1 until 60 do
     board[i] := 0;
  for i := 1 step 1 until piece count do
     unused[i] := true 
  solution count := piece number := 0;
  up (1, 1);
END OF RUN:
  end inner block;

close(reader);
close(printer);
end
|
9,
10, 6, 12, 63,
1, 1, -9, 1, 11, 2,
2, 2, 1, 2, 3, 4, 10, 20, 30, 40,
3, 4, 1, 10, 20, 21, 1, 11, 20, 21, -10, -9, -8, 2, 10, 11, 12, 2,
4, 4, 1, 11, 21, 22, 1, -9, -19, -18, 10, 11, 12, 22, -10, -9, -8, -18,
5, 4, 1, 11, 21, 2, 1, -9, -19, 2, 1, 2, -8, 12, 10, -10, 1, 2,
6, 4, 1, 2, 12, 22, 1, 2, -8, -18, 1, 2, 10, 20, 1, 2, -10, -20,
7, 4, 1, 11, 12, 22, 1, -9, -8, -18, 10, 11, 21, 22, -10, -9, -19, -18,
8, 8, 1, 11, 12, 13, 1, -9, -8, -7, 1, 2, 12, 13, 1, 2, -8, -7, 10, 20, 21, 31, 10, 20, 19, 29, 10, 11, 21, 31, 10, 9, 19, 29,
9, 8, 1, -9, 2, 12, 1, 11, 2, -8, 10, 11, 21, 12, -10, -9, -19, -8, 1, 11, 21, 12, 1, -9, -19, -8, 1, 11, -9, 12, 1, 11, -9, -8,
10, 8, 1, 2, 3, 12, 1, 2, 3, -8, 10, 20, 30, 11, -10, -20, -30, -9, 1, 11, 21, -9, 1, -9, -19, 11, 11, 1, 2, 3, -9, 1, 2, 3,
11, 8, 1, 2, 3, 13, 1, 2, 3, -7, 10, 20, 30, 1, -10, -20, -30, 1, 1, 11, 21, 31, 1, -9, -19, -29, 10, 1, 2, 3, -10, 1, 2, 3,
12, 8, 1, 2, 11, 12, 1, 2, -9, -8, 1, 2, 10, 11, 1, 2, -10, -9, 1, 10, 11, 20, 1, 10, 11, 21, 1, -10, -9, -20, 1, -10, -9, -19,
|