I've been searching for a while to try and arrive at some sort of solution for a problem that is currently roadblocking a task I'm trying to complete. I've come across a few solutions in other programming languages that I really can't understand despite my attempts at doing so. I've also seen a lot of terminology surrounding this problem such as permutations, refactoring, subset sums, coins in a dollar, etc.
If I'm going about this the wrong way, please do feel free to let me know.
Here's the problem in a nutshell:
Given a set (array) of numbers,
ex: 2, 3, 7, 14
,
how could I find what combinations of those numbers add up to (or equal) a specific sum, ex: 14
.
An example of some of the potential combinations for the above example numbers:
3 + 3 + 3 + 3 + 2
7 + 3 + 2 + 2
7 + 7
14
Since the problem I'm trying to solve is in PHP, I'd love if there were a solution that could be offered in that language. If not, even if someone could better explain what the problem is that I'm trying to solve, and potential methods of doing so, I'd be greatly appreciative.
Or again if I might be going about this the wrong way, I'm all ears.