Given a single digit integer and a three digit integer, output a mathematical formula that uses only the single digit and a given list of operators to equal the three digit integer.
Input: A one digit positive integer (1-9
) and a three digit integer (100-999
)
Output: A mathematical formula meeting the following requirements:
- The only number used is the one digit integer
- There no more than 15 instances of that integer (Prevents trivial solutions of the format
(a+a+...+a+a)/a=n
) - The mathematical solution of the formula is the three digit integer
- The only operations allowed are as follows:
- Addition:
1+1
- Subtraction:
2-2
- Multiplication:
3×3
,3*3
,(3)3
- Division:
4÷4
,4/4
- Exponentiation:
5⁵
,5^5
,5**5
- Concatenation:
66
,6||6
- Brackets:
(7+7)
- Addition:
Clarifications:
- Input and Output can be in any standard format.
- The symbols for each operation do not need to be what is shown above; they can be whatever makes sense for your language.
- Explain any input or output formats that you think may not be immediately understood.
- Standard loopholes are forbidden.
- If your output doesn't follow the standard order of operations, it shouldn't matter but do make a note. It would help to include brackets as needed to make the order clear.
- You can not concatenate calculated values:
(8+8)8
is128
, not168
. However,88+88−8=168
is valid. - You may assume the input will always be valid.
- You may assume a valid output will always be possible.
- It does not have to be the shortest possible formula so long as it's valid and uses <16 instances of the single digit
Examples:
Input Output [1,123] 11^(1+1)+1+1 999,2 (2+2/2)2×222/2 3 729 3^(3+3) ['4','300'] ['|','+','**'] where there is a 4 before and after each element and | is concatenate. (4|4+4**4 = 44+4**4 = 44+256 = 300) 255 5 ((5×(5×(5+5)))+5) 6 333 6*666/(6+6) 7,952 7×(7+((7+7)/7)7)+7 8|517 8 × 8 × 8 + 8 − ( 8 + 8 + 8 ) / 8 999 9 999
Scoring
This is code-golf so the shortest code wins.