View Single Post
  #2  
Old 07-14-2006, 09:55 PM
upsilon upsilon is offline
Shmoo
upsilon's Avatar
Join Date: Dec 2005
Location: Birmingham, Alabama
Posts: 58
upsilon is on a distinguished road
I think its only coincidence that they are the same, and only coincidence that they are the greatest donation.

That doesnt not calculate the greatest value of them all. It repeatedly sets the MaxSecond var to the latter of any two pairs of values if the latter is the largest. Nothing is ever compared with MaxSecond, so there is no reason to think that the last value of MaxSecond is actually the largest of all the values ever assigned to in the iteration.

I say you just toss out whatever code you have for calculating the two, and rewrite it.

I dont see the Maximum value being calculated here, so maybe theres a chance its being calculated after this, which would be the same as if the check in this one didnt even exist.

No insult intended, but that code makes absolutely no sense.

Here, this may help:
NPC Code:

function maxDonation(donations) {
enum { amount,name };
temp.largest = donations[0]; //need a starting point
for(temp.i = 1; temp.i < donations.size(); temp.i++) { //notice the count starts at 1
temp.current = donations[temp.i];
if (temp.current[amount] > temp.last[amount]) { //if the largest is not larger than the current donation....
temp.largest = temp.current; //update accordingly
} //if
} //for
return temp.largest;
} //function


now, to calculate the largest and second largest, you only have to do a couple things:
1) pair the amounts and the names in a list; amounts first, names second.
2) assign the result of passing this list to the function above, to the MaxDonater variable
3) remove MaxDonater from the list.
4) assign the result of applying the function to the newly updated list to MaxSecondDonater. MaxDonater isnt in the list, so it cant be duplicated in MaxSecondDonater

hope this helps.
__________________
Health nuts are going to feel really stupid someday, lying in hospitals dying of nothing. - Redd Foxx

Last edited by upsilon; 07-14-2006 at 10:40 PM..
Reply With Quote