2 elements in an array, that add up to a given amount
Posted: Sat Jun 10, 2023 12:46 am
Hi,
The idea is to pass the values of a field into an array, and then try every pair of elements, to see if their sum compares to a target amount.
So if the target amount is 7, and the array is
{
4,
9,
2,
18,
3
}
, the pair { 4, 3 } would be returned, because they sum up to 7.
I know how to do it, based on google searches. But I was wondering if there was anything in HMG or some native Harbour functions that make this look easier or more elegant.
The idea is to pass the values of a field into an array, and then try every pair of elements, to see if their sum compares to a target amount.
So if the target amount is 7, and the array is
{
4,
9,
2,
18,
3
}
, the pair { 4, 3 } would be returned, because they sum up to 7.
I know how to do it, based on google searches. But I was wondering if there was anything in HMG or some native Harbour functions that make this look easier or more elegant.