yackles
January 24th, 2008, 01:23 PM
I am doing my taxes and have a long list of fractional shares sold as a result of dividend reinvestment. In order to reconcile the sale transactions, I need to be able to assemble the fractional purchases on reinvestment with the sales. Given the volume of reinvestments, and share fractions out to four decimals, this is not trivial to do by hand. The problem simplifies to the below:
Is there a simple script to identify all elements, if any, of an array that sum to a target number?
Specifically,
Inputs:
1. arbitrarily long comma-delimited list of real numbers, x1 .. xn
2. target number, y (can be last element of input list)
Output: all sub-arrays adding to y or "NULL" if none
E.g., with y last element of input list
Input:
1, 2, 3, 4, 5, 6, 7, 8, 9, 7
Output:
7
1, 6
2, 5
3, 4
1, 2, 4
Cheers,
Mike
Is there a simple script to identify all elements, if any, of an array that sum to a target number?
Specifically,
Inputs:
1. arbitrarily long comma-delimited list of real numbers, x1 .. xn
2. target number, y (can be last element of input list)
Output: all sub-arrays adding to y or "NULL" if none
E.g., with y last element of input list
Input:
1, 2, 3, 4, 5, 6, 7, 8, 9, 7
Output:
7
1, 6
2, 5
3, 4
1, 2, 4
Cheers,
Mike