In this variant of the Four fours puzzle your should use up to
x's (and no other number) and a defined set of operations to reach every number from 0 to 100. If
x = 4 then you can use up to four
4s and this question becomes the classic four fours puzzle (except you can use up to four 4s rather than having to use exactly four of them). We assume
1 < x <= 9.
In this version, only the following operators are allowed:
- Addition (
+), Subtraction (
-), Multiplication (
*), Division (
/). Note this is real division, so that
5/2 = 2.5.
- Exponentiation (e.g. 4^4) as this would involve no extra symbols if written normally by hand.
- You can make new integers by concatenating
xs. E.g. you can make the integers
4, 44, 444, 4444.
You may also use parentheses to group numbers simply in order to control the order of evaluation of the operators. You can't for example combine parentheses with concatenation as in
(4/4)(4/4) = (1)(1) = 11.
No other symbols may be used and standard order of operations applies.
Your program should generate, given an
x in the defined range and an
100 inclusive, a correct solution for that input if it exists. Otherwise your code must output something to indicate no such solution exists.
You must be able to run your submission to completion on your machine for any input values of
n in the allowed range. This is code golf, so shortest solution wins.
This old related question uses more operators (and only 4s) and hence all numbers from 0 to 100 are solvable which won't be true for this challenge.
Input and output
Your code takes two integers
n as input and should output a solution (or an indication there is no solution) in any human readable format you find convenient. Input
4 6 would mean "Using up to four 4s, make the number 6" for example. So if the input is
4 6 the output could be