Page 1 of 1 [ 8 posts ] 

wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 220

30 Oct 2014, 8:24 pm

I had to solve this recently--enjoy!

You have a number of outstanding checks, some for identical amounts and find out your balance has gone down less than the sum of your checks. You will be given the target amount and a list of check amounts (with a multiplier if more than one).

In this example, the top line is the sum of a various items beneath it including four checks for $32.53.

Quote:
532.72
298.01
97.24
32.53 4
174.56
70.78
99.28
193.82



auntblabby
Veteran
Veteran

User avatar

Joined: 12 Feb 2010
Gender: Male
Posts: 113,725
Location: the island of defective toy santas

30 Oct 2014, 9:01 pm

:?



Fnord
Veteran
Veteran

User avatar

Joined: 6 May 2008
Age: 67
Gender: Male
Posts: 59,873
Location: Stendec

30 Oct 2014, 9:02 pm

Are you asking us to do your homework for you?


_________________
 
No love for Hamas, Hezbollah, Iranian Leadership, Islamic Jihad, other Islamic terrorist groups, OR their supporters and sympathizers.


wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 220

31 Oct 2014, 6:05 am

Fnord wrote:
Are you asking us to do your homework for you?


No, I've done it already and will post my solution in about a week.



Fnord
Veteran
Veteran

User avatar

Joined: 6 May 2008
Age: 67
Gender: Male
Posts: 59,873
Location: Stendec

31 Oct 2014, 7:53 am

Riiiiiight ... :wink:


_________________
 
No love for Hamas, Hezbollah, Iranian Leadership, Islamic Jihad, other Islamic terrorist groups, OR their supporters and sympathizers.


wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 220

01 Nov 2014, 6:36 am

Fnord wrote:
Riiiiiight ... :wink:


Quote:
Diff List of items Considering 318 arrangements
0.00 32.53 * 2 + 174.56 + 99.28 + 193.82
0.41 298.01 + 32.53 * 2 + 70.78 + 99.28
1.63- 298.01 + 97.24 + 32.53 * 2 + 70.78
2.04- 97.24 + 32.53 * 2 + 174.56 + 193.82
3.68 97.24 + 174.56 + 70.78 + 193.82
4.03 32.53 * 3 + 174.56 + 70.78 + 193.82


Like I said, I solved this already. The script tries (almost) everything and displays the first 50 rows. The answer to my sample data from first post is on the top line where Diff =0.00.



wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 220

07 Nov 2014, 10:37 pm

After reading the target amount off the first line, the script builds a table with the candidate amounts, multipliers, and a try that is initially zero. Items w/o a multiplier are given 1, but 1 will be added to each multiplier before stored in the table. How ever many times an item can appear, it can also appear not at all or zero times.

When all items have been stored in a table, the product of all multipliers is found and will be the terminal count for the next loop.

For each iteration in the next loop, each will have a "do until" loop where carry is zero. One is added to the "try" of the first item and, if it is equal to the multiplier for that item, try is zeroed, carry=1, and a subscript is incremented to go through the loop on the next column. Still in that loop, the sum of each item times its "try" is found.

A second table is built containing the absolute value of the difference between that sum and the target, its sign, and a text field describing what was done.

Coming back from a sort, the first few lines are displayed and the tries with the smallest differences between that sum and the target are displayed first.



wbport
Sea Gull
Sea Gull

User avatar

Joined: 16 Sep 2012
Gender: Male
Posts: 220

10 Nov 2014, 7:38 am

My solution is here. Change all dollar signs to less than, all percents to greater than, then save it as a file ending in .html.