P is for Practical PerlMonks

### Comment on

 Need Help??
Almost all my solutions to various maze-like perlgolf competitions have been recursive. For example, the rush-hour problem, where given a state of cars on a 'road', move them around until you can get a particular car out of the jam.
```sub g{my(\$b,\$r)=@_;\$s{\$b}++||map{\$p='.'x8x/[A-Z]/;\$s||=\$r x\$b=~/\$c
/||g(\$n=\$b,"\$r\$c ".(\$n=~s/\$_((\$p\$c)+\$p)(?!\$_)(\$c| )/\$3\$1\$_/s-2*/ /).\$/
+)for\$",\$c=\$_}\$b=~/\w/g;\$s}\$_=g\$_
Look here for the rules, and links to the other solutions.

I can't think of a way to solve this sort of thing iteratively, unless you're willing/planning to take forever. And I think the solutions for that problem illustrate the terseness available to recursion to solve quite an awkward problem. (my solution was 170-odd characters - the winning solution under 140!). And my 500MHz machine still solved the problems in a reasonable length of time.

Also, isn't the regular expression engine recursive?

In reply to Re: Behold! The power of recursion. by Jasper
in thread Behold! The power of recursion. by DigitalKitty

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-02-25 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When it is dark outside I am happiest to see ...

Results (314 votes). Check out past polls.

Notices?