The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

# Algorithms

## Backtracking

Problem :-
Given a set of candidate values in an array & a target x, find all possible ways in which candidate values can be added to get x. We can use each candidate value any number of times.
Consider the candidate values as { 2, 3, 6, 7 } & target ( x ) = 8
Possible ways are :-
2 + 2 + 2 + 2 = 8
2 + 3 + 3 = 8
2 + 6 = 8

Solution :-
First we will find if there exists solution(s) starting from first candidate value and that value must be present in the solution one or more times.
We will start iterating over the candidate values and check if summing up those values lead to a solution. If at any point of iteration we exceed the target value, then we backtrack and try out other candidate values. This process continues till we find a solution.
Then we will move forward and try to find all solution(s) starting from second candidate value and again that value must be present in the solution. We will follow the same steps as described above.
See the implementation below.