Shortest path to sum with given operations

25 Views Asked by At

(Apologies since this was likely asked before, but I cannot find it. )

Is there a way to find the shortest path from some value V to some destination value D using only addition of values from a given set of numbers S?

For example, starting value V = 0. Destination value D=5. Allowed operation is only addition (+) and only values from the following set: S={4,-3}

The solution is 0+4+4-3=D (or any other ordering of these numbers), but nevertheless, requires at least 3 operations.

Another example, starting value V = 0. Destination value D=4. Allowed operation is only addition (+) and only values from the following set: S={3,-7} D=0+3+3+3+3+3+3-7-7=4. It requires at least 8 operations.

Finally, starting value V = 0. Destination value D=2. Allowed operation is only addition (+) and only values from the following set: S={3,-6, -9} Is impossible to complete.

So the question is: How to find the shortest path to get from starting value V to destination value D, by only adding numbers from set S?

How is this called? How can this be figured out? Many thanks!