Re: new new challenge
- Posted by Robert Craig <rds at RapidEuphoria.com> Aug 20, 2001
- 442 views
Ross Boyd writes: >Your solution averaged 6.50 secs and > my ugly one below was 3.85 secs on a P3-450. It depends on the distribution of numbers that you feed in. I find the two functions are about equal, given a series of numbers 1 to 100,000,000. (To be really fair you might go to 1.07 billion, but that takes too long). The long chain of if's looks bad until you realize that 50% of the time you will quit after just one and_bits() test, 75% after just two, 87.5% after three etc. The simple function *always* does one and_bits(), one xor_bits(), and one subtraction. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com