Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Tricky math problem ...

by hdb (Monsignor)
on May 04, 2019 at 19:04 UTC ( [id://1233363]=note: print w/replies, xml ) Need Help??


in reply to Tricky math problem ...

Another version:

use strict; use warnings; my $grid = join('', <DATA>); $grid =~ s/\n//g; my $n = sqrt(length $grid); my @sqs; while( $grid =~ /(.*?)[.x]/ ) { my $sq = ('A'..'Z')[scalar(@sqs)%26]; my $pos = length $1; substr( $grid, $pos, 1 ) = '.'; my $i = 1; my $x = $pos%$n; my $y = int $pos/$n; $i++ while $x+$i < $n and $y+$i < $n and join( '', map { substr($gri +d,$_*$n+$x,$i+1) } $y..$y+$i ) eq '.' x (($i+1)*($i+1)); substr($grid,$_*$n+$x,$i) = $sq x $i for $y..$y+$i-1; push @sqs, [ $x+1, $y+1, $i, $sq ]; $sq++; } print substr($grid,$n*$_,$n)."\n" for 0..$n-1; print "@$_\n" for @sqs; __DATA__ ............ .........x.. ......x..... ..x......... x........... ....x....... .......xx... ..x......... ..x.....x... ..x......... .x.....x.... ............

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-29 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found