Perl 'Medium' Quiz-of-the-Whatever for 2009-08-11 : Plusified Equations
Shlomi Fish <shlomif-ik1l9ssToec+JF/[email protected]> Tue, 11 Aug 2009 17:55:06 +0300
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
IMPORTANT: Please do not post solutions, hints, or other spoilers
until at least 60 hours after the date of this message. Thanks.
---------------
We are given two positive integers $L and $R we need to find Plusified
expressions of both for which Eval($E_L) == Eval($E_R). So what is a plusified
expression? It is an expression where we can choose whether to add a single
"+" between any consecutive digit. So for example the number 123 has the
following plusified expression:
* 123
* 12+3
* 1+23
* 1+2+3
So if we are given 123 and 96 we can form the following plusified equation:
* 12+3 == 9+6
Your mission is to write a Perl program (or an equivalent program in any
programming language) that will find all solutions to the plusified equation
of two numbers given as input. To normalise the output we'll rule that:
1. The equations should be given one at each line.
2. They will be sorted so consecutive digits will take precedence over "+"'s.
3. A "+" has no surrounding spaces.
4. The = sign does have a preceding and following space.
As an example:
{{{{{{{{{{{{{
$ ./plusified-equation 12341234 1010
1+23+41+2+34 = 101+0
1+2+3+4+1+2+3+4 = 10+10
}}}}}}}}}}}}}
Enjoy!
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Best Introductory Programming Language - http://xrl.us/bjn84
God gave us two eyes and ten fingers so we will type five times as much as we
read.