Re: [SPOILER] Solution for QOTW 23
Jonathan Weed <jweed-Zy/[email protected]>
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
Mark Jason Dominus wrote:
> I'm really pleased with this. And I'm glad about the 60-hour
> moratorium, because my first couple of solutions weren't nearly as
> excellent.
>
> #!/usr/bin/perl -l
>
> print $_ = "()" x shift;
> print while s{^ ( \(+ ) ( \)+ ) \( }
> {"()" x (length($2) - 1)
> . "(" x (length($1) - length($2) + 2)
> . ")"
> }xe;
>
>
>
> __END__
> That's all.
>
> :) :) :D
>
Despite extensive fiddling, I don't have any intuitive notion of why
this should produce all strings. I can see how a valid start string,
when run through the s/// will produce another valid string, but I can't
wrap my head around precisely what's happening or, even more murky, how
you thought this one up. Can you shed some light for the not-quite-perl
/algorithmic-hackers?
jweed
--
http://www.justicepoetic.net/