Too bad! I had such a beautiful equation, but I lost all my =+-*
, so there is nothing left but a chain of digits, looking like a number: 7512
. But was it 7+5=12
or 7-5=1*2
or 7=5*1+2
or 7=5+1*2
? Or are there even more valid possibilities?
Your task: For a given positive integer number, return the number of true equations containing the digits of that number in the given order, using plus and minus and multiplication operators.
- dot-before-dash calculation is used, so 1+2*3 is 7, not 9
- plus and minus are only allowed as operators, not as (prefix) sign, so neither negative numbers in the equation nor superfluous plus padding
- no division to keep rules simple
- input numbers are integers ranging from
0
to999999
- no leading zeroes, neither in input, nor in equations
- operators are allowed to appear several times, but of course only exactly one
=
- a single digit as input leads to
0
as output, because you can't do any equation with it - the smallest number to return
1
is11
(equation is1=1
) - don't underestimate the possibilities for higher numbers like
1111
(10
possible equations:11=11 1*1=1*1 1+1=1+1 1-1=1-1 1=1*1*1 1=1-1+1 1=1+1-1 1*1*1=1 1-1+1=1 1+1-1=1
- you are free to use anything from brute force to intelligent algorithms, execution time is irrelevant, just don't use many bytes of code, because we are golfing
Check your code with these examples:
7 --> 0
42 --> 0
77 --> 1
101 --> 3
121 --> 1
1001 --> 12
1111 --> 10
7512 --> 5
12345 --> 5
110000 --> 203
902180 --> 37
1+0=1
,1-0=1
,1=01
. \$\endgroup\$+
as a unary prefix operator is also not allowed? Please clarify \$\endgroup\$