#!/usr/bin/perl # http://perlmonks.org/?node_id=1121552 use strict; use warnings; for my $y ( 1..25 ) { local $_ = tile(5,$y); /1$/ and !/-/ and print "success 5,$y\n"; } sub tile { my ($w, $h) = @_; my $wm1 = $w - 1; local $_ = ( '-' x $w . "\n" ) x $h; s/-/1/; 1 while # print("$_\n"), s/1..{$w}\K-/1/s || s/1\n.*\K-(?=\n)/2/ || s/1(?=.*$)\K-/4/ || s/2.{$wm1}\K-/2/s || s/2.{$wm1}\n\K-/1/ || s/-(?=2.*$)/3/ || s/-(?=..{$w}3)/3/s || s/^.*\K-(?=3)/2/ || s/-(?=.{$wm1}\n3)/4/ || s/-(?=.{$wm1}4)/4/s || s/^.*4\K-/1/ || s/-(?=.{$w}4\n)/3/s; return $_; }