I'm trying to make a card game called Tablic, and I'm struggling with logic.
Simplified, it comes to this:
- I have an array filled with numbers from 1 to 14. (array size doesn't matter, but since we have 52 cards it can't be larger than that) - random example: [2,9,2,9,8,11,14,7]
- I need to check if all elements of array can be used in addition (no other math operation is allowed) to get one specific number (1 < number < 14)
Few examples:
[2, 1, 5, 4] == 6 //true --> 2+4==6; 1+5==6 .. all elements of array are used
[2, 1, 3, 5, 4] == 6 //false --> we can not calculate 6 using all elements, there is always one or more extra ... 2+4==6; 5+1==6; .. 3 is unused!! ... or .. 1+2+3==6; 4 and 5 are unused
[5, 2, 10, 3] == 10 //true --> 2+3+5==10; 10==10 .. again, every number from array is used, so true
[6, 4, 3, 4, 9, 3, 2, 12, 6, 8, 10, 3, 2] == 12 //true --> 6+6==12; 12==12; 8+4==12; 9+3==12; 10+2==12; 2+3+3+4==12 ... all numbers from array used
I hope I was clear enough (and I hope I am at the right place to ask questions like this)