I'm not a big fan of the glob trick - there's always the possibility something matches (although for the given pattern, that's pretty unlikely). But just for kicks, I compared your solution with mine:
$ /usr/bin/time ./perlmouse ; /usr/bin/time ./ray_johnson
-9 + 8 * 7 + 654 * 3 - 2 - 1 == 2006
9 + 8 * 7 + 654 * 3 - 21 == 2006
9 + 8 * 7 * 6 * 5 - 4 + 321 == 2006
9 * 8 - 7 + 654 * 3 - 21 == 2006
56.60user 0.19system 2:04.01elapsed 39%CPU (0avgtext+0avgdata 0maxresi
+dent)k
0inputs+0outputs (356major+87minor)pagefaults 0swaps
-9+8*7+654*3-2-1 == 2006
9+8*7+654*3-21 == 2006
9+8*7*6*5-4+321 == 2006
9*8-7+654*3-21 == 2006
56.98user 3.45system 2:43.21elapsed 41%CPU (0avgtext+0avgdata 0maxresi
+dent)k
0inputs+0outputs (398major+21556minor)pagefaults 0swaps
The running time is about the same, but your solution uses a lot more memory, as it makes a list of all possible expressions to test before making the first test, while my solution tests each expressions right after it is constructed. My solution has a lot less pagefaults.
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.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, 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?
See Writeup Formatting Tips and other pages linked from there for more info.