2

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.

Ref: Wikipedia Numbers_round

zx8754
  • 52,746
  • 12
  • 114
  • 209
Rahul Singh
  • 69
  • 1
  • 5
  • 6
    What did you try so far? It will be better to explain the problem you are trying to solve with expected results. Not many ppl will want to read code to understand the question. Also see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Bulat Sep 19 '16 at 07:11
  • Number of possibilities: `n<- length(l); factorial(n)*4^n `. this will be a hassle to compute with not so large `l` – Tensibai Sep 19 '16 at 08:56
  • 1
    This repo might be useful: https://github.com/rvedotrc/numbers , solution is using C. – zx8754 Sep 19 '16 at 09:57
  • 1
    Another useful post: http://stackoverflow.com/questions/15293232/how-to-design-an-algorithm-to-calculate-countdown-style-maths-number-puzzle – zx8754 Sep 19 '16 at 10:24
  • Welcome to StackOverflow. Please read and follow the posting guidelines in the help documentation. [on topic](http://stackoverflow.com/help/on-topic) and [how to ask](http://stackoverflow.com/help/how-to-ask) apply here. StackOverflow is not a coding or tutorial service. – Prune Sep 22 '16 at 17:26

0 Answers0