I opted for the "abuse regex" approach (because it's fun, and you can do it incrementally one s/// at a time until it works):
#!/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 $_; }
which prints
success 5,1 success 5,3 success 5,7 success 5,9 success 5,11 success 5,13 success 5,17 success 5,19 success 5,21 success 5,23
Sure looks like multiple solutions exist.
In reply to Re: [OT (though it might involve some Perl programming)] One for the weekend. (Updated: significant typo!)
by Anonymous Monk
in thread [OT] One for the weekend. (Updated: Answer posted!)
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |