7 return join("\n", @rows) . "\n";
12 my $dim =()= $str =~ /(\n)/g;
14 for my $y (0 .. $dim-1) {
15 for my $x (0 .. $dim-1) {
16 $newstr .= substr($str, $y + ($dim+1)*($dim - $x - 1), 1);
25 return rows2str(map { join('', reverse split //) } split /\n/, $str);
29 my ($str, $count) = @_;
30 return $count == 4 ? flip($str) : rotate($str);
34 $_[0] =~ /\A(.*?)\n/xms;
43 my ($id, $data) = /\ATile\s+(\d+):\n(.*?\n)\n?\z/xms;
45 push @{ $top2tile{top_side($data)} }, $id;
46 $data = rotate_or_flip($data, $_);
51 for my $row (keys %top2tile) {
52 next if @{ $top2tile{$row} } != 1;
53 $single_ids{ $top2tile{$row}->[0] }++;
56 my @corners = grep { $single_ids{$_} == 4 } keys %single_ids;
57 print join('*', @corners), '=', eval join('*', @corners), "\n";