Re: [C][OT] erroneous fprintf output
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 05/14/04
- Next message: Francis Glassborow: "Re: Help with string containing null ('\0') chars ..."
- Previous message: velthuijsen: "returning variables: shouldn't most have const added?"
- In reply to: Curley Q.: "Re: [C][OT] erroneous fprintf output"
- Next in thread: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- Reply: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- Reply: Curley Q.: "Re: [C][OT] erroneous fprintf output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 May 2004 00:05:20 +0100
In message <40A3F1DA.20503@bogus.net>, Curley Q. <curleyq@bogus.net>
writes
>Have I correctly implemented your suggestions in the code below?
Not quite you combined two alternatives. First I suggested a better way
to do a random shuffle in C. Second I suggested an algorithm without
shuffling. Interestingly it seems that there is never a cross over. IOWs
the difference between the sum of the square-roots of all the odd number
less than n and of all the even numbers less than n never differs by as
much as the square root of (n+1) [or perhaps the cross over is for a
very large value of n, I will have to think about that (and I guess this
problem could go into my project repository)
As the sum of the square roots of even numbers is greater than the sum
of the square roots of odd numbers and there is no cross over we need a
different algorithm. So try:
find the total of all the square roots of the even numbers (total_even)
and likewise for the odd numbers (told_odd). Compute half the difference
(call it half_diff).
Now rerun keeping running totals for odd (sum1) and even (sum2) until
the difference first exceeds half_diff. At that point switch and add the
square roots of the remaining even numbers to sum1 and the remaining odd
ones to sum2.
I can think of various ways to tune this further.
Thanks for the idea.
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: Francis Glassborow: "Re: Help with string containing null ('\0') chars ..."
- Previous message: velthuijsen: "returning variables: shouldn't most have const added?"
- In reply to: Curley Q.: "Re: [C][OT] erroneous fprintf output"
- Next in thread: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- Reply: Robert W Hand: "Re: [C][OT] erroneous fprintf output"
- Reply: Curley Q.: "Re: [C][OT] erroneous fprintf output"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|