Results: Calculate square roots
OK, I' m unable to post the submissions in this thread, for known reasons, but I hope that every contestant can post their submission here for review.
Overview
Most people used the Newton-Rhapson method of solving equations. You can google for information about the algorithm, it's not advanced at all.
If you set up the equation
x^2 - a =0
It will have one root x = sqrt(a). The equation is solved with Newton-Rhapson's method.
Two different styles of was used to implement the iteration. One involved one general template and one specialization to stop the iteration (which I used in my best solution and also used by the winner). Another interessting implementation was invented by xErath, who used lots of template arguments to obtain the correct number of iterations.
Results
Everyone listed in the fist post of the original thread has submitted working solutions and are good coders -- this isn't trivial.
However, two persons submitted solutions that worked for every value of x >= 1 (I didn't get the time to do extensive tests) -- Okinrus and Fordy
Of these two, Fordy has the smallest submission. Good work! Fordy is the winner! :cool:
While his submission was short, every solution can be made shorter! Here are some of my thoughts:
- Used 'int' and 0/1 instead of 'bool' and true/false
- >>1 instead of /2 (getsrid of parentheses)
- Somewhat different #defines
But this doesn't matter as he was the best anyway!
I'm really sorry that I was unable to judge xErath's last submission, because it was really short as well!