A pentomino is a polyomino that consists of 5 squares. There are 12 pentomino shapes,
if you don't count rotations and reflections. Most pentominoes can form their own mirror image through
rotation, but some of them have to be flipped over.

        I                                                                        
        I     L       N                                                 Y        
 FF     I     L      NN     PP     TTT              V       W     X    YY      ZZ
FF      I     L      N      PP      T     U U       V      WW    XXX    Y      Z 
 F      I     LL     N      P       T     UUU     VVV     WW      X     Y     ZZ


A Pentomino tiling is an example of an exact cover problem and can take on many forms.
A traditional tiling presents an 8 by 8 grid, where 4 cells are left uncovered. The other cells are covered
by the 12 pentomino shapes, without overlaps, with every shape only used once.

The 4 uncovered cells should be chosen at random. Note that not all configurations are solvable.



Task
Create an 8 by 8 tiling and print the result.



Example
F I I I I I L N
F F F L L L L N
W F - X Z Z N N
W W X X X Z N V
T W W X - Z Z V
T T T P P V V V
T Y - P P U U U
Y Y Y Y P U - U


Related tasks
 Free polyominoes enumeration


 
import sat, util.
rotate(Q) = Res => % rotate right by 90 degrees
    NZ = len(Q[1]), NS = len(Q), Res = new_array(NZ,NS),
    foreach(Z in 1..NZ, S in 1..NS) Res[Z,S] = Q[S,NZ+1-Z] end. 
 
matprint(Q) =>
    NZ = len(Q), NS = len(Q[1]), 
    foreach(Z in 1..NZ, S in 1..NS)
        printf("%d|", Q[Z,S]),
        if S=NS then nl end
    end, nl.
 
generate(Res) =>
    P0 = [{{1,1,1,1}, % L
           {1,0,0,0}},
          {{0,1,1,1}, % N
           {1,1,0,0}},
          {{1,1,1,1}, % Y
           {0,1,0,0}},
          {{1,1,0}, % F
           {0,1,1},
           {0,1,0}},
          {{1,1,1}, % T
           {0,1,0},
           {0,1,0}},
          {{0,0,1}, % W
           {0,1,1},
           {1,1,0}},
          {{1,1,1}, % P
           {1,1,0}},
          {{0,0,1}, % V
           {0,0,1},
           {1,1,1}},
          {{1,0,1}, % U
           {1,1,1}},
          {{1,0,0}, % Z
           {1,1,1},
           {0,0,1}},
          {{1,1,1,1,1}}, % I
          {{0,1,0}, % X
           {1,1,1},
           {0,1,0}}],
    Np = len(P0), P = [],
    foreach(I in 1..Np)
        VarI = [P0[I]],
        foreach(_ in 1..3) VarI := [rotate(head(VarI))|VarI] end,
        P := [VarI|P]
    end,
    Res = P.
 
main =>
    N = 8, M = new_array(N+4,N+4),
    foreach(R in N+1..N+4, C in 1..N) M[R,C] #= 0 end, 
    foreach(R in 1..N, C in N+1..N+4) M[R,C] #= 0 end, 
    generate(P),  % P[1] = X-Pentomino, then P[2] = I, P[3] = Z, and so on U, V, P, X, W, T, F, Y, N, L
    Np = len(P), M :: 0..Np, 
    foreach(I in 1..Np) count(I, vars(M), 5) end, % 12 pentomino
    Idx = new_list(Np), % X has 1 rotation variant, I and Z each 2, the rest 4:
    Idx[1] #= 1, [Idx[2],Idx[3]] :: 1..2, Idx :: 1..4,
    DZ = new_list(Np), DZ :: 0..N-1, % translation of I.th pentomino
    DS = new_list(Np), DS :: 0..N-1,
    foreach(I in 1..Np, J in 1..4) % Constraint only if Idx[I] #= J!
        NZ = len(P[I,J]), NS = len(P[I,J,1]), 
        foreach(DZI in 0..N-1, DSI in 0..N-1, Z in 1..NZ, S in 1..NS, P[I,J,Z,S]=1) 
            (Idx[I] #= J #/\ DZ[I] #= DZI #/\ DS[I] #= DSI) #=> M[DZI+Z,DSI+S] #= I
        end
    end,
    solve(vars(M) ++ DZ ++ DS ++ Idx),
    Chr = " XIZUVPWTFYNL",
    foreach(Z in 1..N)
        foreach(S in 1..N)
		    printf("%c|", Chr[1 + M[Z,S]]) 
    	end, nl
    end.
 