Problem: Given a number between 0 and 6, which combination of 4, 2, 1 will equal the given number. A number can only be used once (cannot just do 1 for 6 times to get a given number of 6).
Examples:
Value = 6
4 = 1
2 = 1
1 = 0
Value = 4
4 = 1
2 = 0
1 = 0
Value = 3
4 = 0
2 = 1
1 = 1
Current forumlas, where given number is 6:
4 = Floor(6/4)
2 = Floor(6%4)/2
1 = Floor[(6%4)%2]/1
Given that this is a pattern, how would I simplify my formulas? Does this pattern have any particular name?
You can follow a greedy approach. Start subtracting the largest element in the list (4-2-1 here) that is also smaller than the number you want to decompose from your number and repeat until you reach 0.