Re: Perl 'Medium' Quiz-of-the-Whatever for 2009-08-11 : Plusified Equations
Josh Narins <[email protected]> Wed, 07 Oct 2009 06:36:37 -0400
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
I set up my solution about a half year before the contest was announced, although I would prefer if no one requests any answers to future contests at this time. Mine started when I noticed that my telephone number was a true equation. Someone mentioned at work that the current calendar day was a perfect square, or something quite like that, I mentioned my telephone number, and someone asked for a programmatic solution. My solution allows up to eight operators, +, -, *, /, **, ^, & and I, but as a party trick, the first four are the default. It's also a recursive solution around the number of digits, so you can blow out your memory if you could think of some more operators. Like the previous answer, I use eval. I also skip all numbers that begin with 0 but basically because this is designed as a party trick, and some people simply don't appreciate being told 1+01=2. I also eliminate 0. I also didn't care where the = was, so I try it at all meaningful locations. Since it is recursive, I currently limit it to 10 digit numbers: http://www.flowersofpeace.com/telephone Also, if you have a mobile phone and live in NYC, you might like http://www.flowersofpeace.com/weather Someone nearby here at work did the same problem with an iterative solution