Re: Perl Quiz of the Week #23
Daniel Martin <martin-+m399P62/[email protected]>
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
colin.rafferty-/PgpppG8B+R7qynMiXIxWgC/[email protected] writes: > Of course, what I'd really like is to have a (non-exponential) > algorithm that calculates the number of lines in the answer. So far, > I have the following results. Heh - I hadn't seen your message when I sent mine, but a quick and dirty way to do the calculation if you've got my parencheck.pl script from that message is: perl -le 'print q[()] x 16' | perl parencheck.pl And then read the error message. Or you can rip out binom and catalan from that script and come up with a nicer interface. Given the exponential(*) nature of this particular problem, I wouldn't worry about speed and focus instead on program elegance and simplicity this time. (*) The number of output lines is approximately (4**n)/(sqrt(Pi) * n**1.5) from: http://mathworld.wolfram.com/CatalanNumber.html