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:


  • 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 is 128, not 168. 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


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


This is so the shortest code wins.

  • \$\begingroup\$ Related, related \$\endgroup\$
    – Laikoni
    Commented May 15, 2018 at 21:17
  • 1
    \$\begingroup\$ @BradC Since it's tagged code-golf and not metagolf, I'd assume it's the former. \$\endgroup\$ Commented May 16, 2018 at 1:25
  • \$\begingroup\$ @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) \$\endgroup\$ Commented May 16, 2018 at 1:30
  • \$\begingroup\$ @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? \$\endgroup\$ Commented May 16, 2018 at 13:32
  • 1
    \$\begingroup\$ 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 codegolf.stackexchange.com/q/82884/194 \$\endgroup\$ Commented May 16, 2018 at 16:14