1

Looking for an algorithm to determine which numbers in a continuous binary number line that are equal to a given sum. For example given the binary numbers 1,2,4,8 which are required to sum to 13? The only answer is 1+4+8.

My solution so far is to subtract the largest number N1 in the number line from the sum S. If result > 0 then a) N1 is one of the numbers used in the sum, b) subtract N1 from S to S1, then repeat with the next largest number is the number line.

My solution works but seems crude, was wondering if there are any better ideas out there. Performance time is not a factor.

0 Answers0