So I've been inspired by this puzzleing SE question to create a similar Code Golf challenge. The basic puzzle format is you must use 4 numbers, such as 5 5 5 5, to equal some other number, such as 35, using only plus, minus, multiply, divide (float division only), factorial, exponent, concatination (I'll grudingly allow concatination of calculations), and parentheses. You may only use the four of the input number (no more, no less), but you may use as many pluses, minuses, multiplies, etc. as you please.

The Challenge

Given one input number, n, can you use it exactly four times to make input number x? If so how? Numbers n and x will be inputed through a form n, x. If a particular input set is not solvable then it should return the word Impossible (case-sensative). This is , shortest code wins.
Edit: This is different from the four fours because this generalizes the problem into any four of the same number, as opposed to any four fours

Expected input-outputs

5, 19 could return (5!-(5*5))/5 or (5-5/5)!-5
4, 30 could return (4+(4/4))!/4
1, 11111 should return Impossible
N.B: these are merely examples, and there are possibly a great many solutions to each input set.

  • 1
    \$\begingroup\$ Can you prove that 1,11111 is impossible? Also, is division, integer division or real division? i.e. is 1/2 0 or 0.5? \$\endgroup\$
    – Jo King
    Sep 1, 2018 at 3:15
  • \$\begingroup\$ May concatenation works on computed value? e.g. Will concat(4×4, 4) yield 164? \$\endgroup\$
    – tsh
    Sep 1, 2018 at 3:17
  • \$\begingroup\$ @tsh, originally no, but for the purposes here I'll allow it. \$\endgroup\$
    – tox123
    Sep 2, 2018 at 14:41
  • 1
    \$\begingroup\$ I don't think this is a duplicate. This is a generalization of the other question \$\endgroup\$
    – MilkyWay90
    Jun 15, 2019 at 20:21


Browse other questions tagged or ask your own question.