This question brought to you by a game I like to play when stuck in long phone meetings.
Given any two times from a 24 hour clock (from 00:00 to 23:59), how many valid mathematical equations can be generated with all of the times in between using only basic arithmetic operations?
Input: two four digit strings (no colon) representing valid times in a 24 hours cycle.
Examples:
For input=0000, 1300
03:26 produces: "0+3*2=6" and "03*2=6" etc.
11:10 produces quite a few, including: "1*1=1+0" and "1=1=1^0" and "1=11^0" etc.
12:24 produces: "1/2=2/4" and "1=(2*2)/4" etc.
Valid operations are:
- addition
- subtraction
- multiplication
- division (floating point)
- exponentiation
- factorial
Other allowable symbols
- Parentheses
- Equal signs
Shortest code wins.
Notes
- The goal is to find the number of valid expressions between two times, not the number of times that contain a valid expression.
- The two times given as input are included in the range of times.
- You may group the digits in any way possible, so "1223" can be "12 23" or " 1 2 23" or "1 223" etc. etc.
- You may use as many parentheses as needed.
- You may use more than one
=sign. For instance, the time11:11has the valid expression1=1=1=1. - If the first time occurs chronologically after the second time, the range of times should wrap as if crossing into the next day.
- The numbers must remain in their original order- you may not re-order the digits.
- When clustering numbers, zero's may absolutely be the front most digit, in which case, they are ignored ("0303" clustered as "03 03" is just two digits with the value of 3.)
- You MAY NOT use the minus sign as unary negation. Therefore, "12:01" does NOT produce "1-2=-(01)", but DOES produce "1-2=0-1".
- You MAY NOT add decimal points to digits. Therefore, "12:05" does NOT produce "1/2=0.5".
- No chaining of factorials- a digit may be followed by at most one "!", no more, otherwise, many times would have infinite solutions. Ex: "5!" is valid but "5!!" is not valid.
0000 1300should equations derived from0000and1300be included in the count? \$\endgroup\$