Problem statement as follows:
Input 1: a list of distinct numbers, l1
Input 2: a single number, t
Output: all the combinations of l1
that can yield t
using +
, -
, *
or "/"
.
We have to arrive at a single result using arithmetic operations on numbers given, e.g.:
l <- c(2,3,4,5)
t <- 6
Output should come as:
6=((2+3)-(4-5))
6=((2+3)-(4-5))
6=((2+3)+(5-4))
6=(((2+3)-4)+5)
6=(((2+3)+5)-4)
6=((2+3)+(5-4))
6=(((2+3)-4)+5)
6=(((2+3)+5)-4)
6=((2*3)*(5-4))
6=((2*3)/(5-4))
6=((5-4)*(2*3))
6=((2/3)*(4+5))
I don't know how I can code this, it would be very helpful if I can get some reference.