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


#!/usr/bin/perl
 
use strict;  # first open space version
use warnings;
 
my $size = shift // 8;
 
sub rotate
  {
  local $_ = shift;
  my $ans = '';
  $ans .= "\n" while s/.$/$ans .= $&; ''/gem;
  $ans;
  }
 
sub topattern
  {
  local $_ = shift;
  s/.+/ $& . ' ' x ($size - length $&)/ge;
  s/^\s+|\s+\z//g;
  [ tr/ \nA-Z/.. /r, lc tr/ \n/\0/r, substr $_, 0, 1 ]; # pattern, xor-update
  }
 
my %all;
@all{ " FF\nFF \n F \n", "IIIII\n", "LLLL\nL   \n", "NNN \n  NN\n",
  "PPP\nPP \n", "TTT\n T \n T \n", "UUU\nU U\n", "VVV\nV  \nV  \n",
  "WW \n WW\n  W\n", " X \nXXX\n X \n", "YYYY\n Y  \n", "ZZ \n Z \n ZZ\n",
  } = ();
@all{map rotate($_), keys %all} = () for 1 .. 3;  # all four rotations
@all{map s/.+/reverse $&/ger, keys %all} = ();    # mirror
my @all = map topattern($_), keys %all;
my $grid = ( ' ' x $size . "\n" ) x $size;
my %used;
find( $grid );
 
sub find
  {
  my $grid = shift;
  %used >= 12 and exit not print $grid;
  for ( grep ! $used{ $_->[2] }, @all )
    {
    my ($pattern, $pentomino, $letter) = @$_;
    local $used{$letter} = 1;
    $grid =~ /^[^ ]*\K$pattern/s and find( $grid ^ "\0" x $-[0] . $pentomino );
    }
  }