(it's just for myself to check values, I only need to use this alone)
[EDIT] Rules :
1. User inputs an array of @numbers, and a @goal
2. The code searches for sums of @numbers that would match @goal value, following these rules :
--The only operation allowed to combine @numbers is sum
--There could be any amount of the same @number involved in sums
--If @goal can't be matched, returns the closest sum available
--[optional] Could work with negative @numbers
Example 1 - Exact goal reached :
-Input :
Code: Select all
{numbers = {1,2,3}, goal=3}
Code: Select all
Found 3 matches :
numbers[1]*3
numbers[1]*1 + numbers[2]*1
numbers[3]*1
Code: Select all
{numbers = {1,2,3}, goal=3.1}
Code: Select all
No match found, closest match = 3 :
numbers[1]*3
numbers[1]*1 + numbers[2]*1
numbers[3]*1
The only calculators I found only took each number once per sum, though I want them to be able to consider more than one of the same number per sum (of course, for this, there needs to be a searching range limit, otherwise the thing would go "3 = 1*1000003 + -2*500000" up to infinity)
I would mainly want to compare arrays containing ~ 20 float numbers between -10 and 10, so I wouldn't need a huge amount of memory for that...
(I hope it's more clear now...)