Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: [OT (though it might involve some Perl programming)] One for the weekend. (Updated: significant typo!)

by Anonymous Monk
on Mar 30, 2015 at 03:01 UTC ( [id://1121761]=note: print w/replies, xml ) Need Help??


in reply to [OT] One for the weekend. (Updated: Answer posted!)

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.

  • Comment on Re: [OT (though it might involve some Perl programming)] One for the weekend. (Updated: significant typo!)
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1121761]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-24 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found