Re: [C][OT] erroneous fprintf output

From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 05/14/04


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


Relevant Pages

  • Re: What is the MOST INTERESTING integer you know?
    ... What number is a square and also the sum of it's square roots? ... in the real domain. ... The only solution to your remakably trivial question is zero. ...
    (sci.math)
  • Re: What is the MOST INTERESTING integer you know?
    ... I hereby propose to raise the intellectual level of this group by ... What number is a square and also the sum of it's square roots? ...
    (sci.math)
  • Re: What is the MOST INTERESTING integer you know?
    ... I hereby propose to raise the intellectual level of this group by ... What number is a square and also the sum of it's square roots? ... -- Reef Fish Bob. ...
    (sci.math)
  • Re: Modular arithmetic question
    ... > solve this problem when the factorization of k is unknown (and k is ... algorithm for computing square roots mod p which ... If you could quickly compute the square roots of -1 mod F_n ... F_n as the sum of two squares. ...
    (sci.math)