Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: ASCII Pattern - Golf

by halley (Prior)
on Sep 19, 2003 at 19:19 UTC ( [id://292743]=note: print w/replies, xml ) Need Help??


in reply to ASCII Pattern - Golf

I wanted to go on a completely different tack using s///, but couldn't get anywhere near as brief a method.
$_=('x'x9 .$/)x9; substr($_,10*(9-$ARGV[1])+$ARGV[0]-1,1)=0; for$a(0..8){for$b(0,8,9,10){s/(?<=$a.{$b})x|x(?=.{$b}$a)/$a+1/esg}} print;
Useless but interesting digression: ...
This is similar to a routine used for pathfinding on game grids. I start at 0. At move 1, here's where I could be, at move 6, here's where I could be, and so on. My routine would be able to avoid barriers in the gameboard and continue to walk around the sides of such barriers. An example barrier of five dashes is added:
$_=('x'x9 .$/)x9; substr($_,10*(9-$ARGV[1])+$ARGV[0]-1,1)=0; substr($_,10*3+3,5)='-----'; # extra barrier for$a(0..8){for$b(0,8,9,10){s/(?<=$a.{$b})x|x(?=.{$b}$a)/$a+1/esg}} print;
This produces (with starting 0 at 2,3):
666666789 555556789 444456788 333-----7 222234567 111234567 101234567 111234567 222234567

--
[ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found