3
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.
Related, related – Laikoni – 2018-05-15T21:17:05.907
1@BradC Since it's tagged [tag:code-golf] and not [tag:metagolf], I'd assume it's the former. – ETHproductions – 2018-05-16T01:25:32.300
@fəˈnɛtɪk Hmm, you're right. The first sentence seems to be at odds with the rest of the challenge though (the second output rule seems to imply that people would be looking for trivial formulas, rather than short ones) – ETHproductions – 2018-05-16T01:30:39.120
@fəˈnɛtɪk I think I must have changed my mind halfway through writing it and it wasn't picked up in the sandbox. Is it better now?
– Engineer Toast – 2018-05-16T13:32:48.803Edit looks good, voted to reopen. No idea how I would do this in T-SQL, though :( – BradC – 2018-05-16T14:23:13.490
1
Adding the exponentiation operator and an outer loop over the number of times the digit is used don't IMO add anything non-trivial over https://codegolf.stackexchange.com/q/82884/194
– Peter Taylor – 2018-05-16T16:14:19.147@PeterTaylor I suppose this is a specialized case of the other. You could just run one of those solutions for 15 different arrays with each value being the input and output the first one that has an output. I didn't find that question in my search but don't disagree with the closure. – Engineer Toast – 2018-05-16T18:04:54.097