digits made of digits and an integer goal. Between any two neighboring digits you may put one of the signs +, -, *, or nothing at all, in which case the digits join into a longer number. The order of the digits stays fixed.
Return every resulting expression whose value (with the usual precedence: multiplication before addition and subtraction) equals goal. Return the expressions as strings without spaces, in any order.
Numbers in an expression must not have leading zeros: 0 is fine, 05 or 00 is not.digits="2024", goal=8 → ['2+0+2+4', '2-0+2+4', '2*0+2*4']
Exactly three expressions give 8: 2+0+2+4, 2-0+2+4 and 2*0+2*4.
digits="105", goal=5 → ['1*0+5', '10-5']
1*0+5 = 5 and 10-5 = 5. 1*05 is not allowed because 05 has a leading zero.
digits="99", goal=1 → []
Two nines only give 99, 18, 0 and 81; none of them is 1.
digits) ≤ 10digits consists of digits onlygoal ≤ 2³¹ - 1digits="2024", goal=8
['2+0+2+4', '2-0+2+4', '2*0+2*4']
Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.