I’m learning Sedgewick’s Algorithms and the examples are all in Java. So I’m converting them to Python for my own understanding.
Here’s the first example I came across in the first chapter, for finding a square root:
x = i
while (x-i/x) > (e):
In : sqrt(4)
In : sqrt(9)
In : sqrt(142857)
I ought to raise an Exception instead of returning None in the beginning. My maths skills have turned painfully rusty — it took me a good 5-10 minutes of reading the example in the book before I understood that it worked, after which I wrote this version without too much trouble.
Hopefully I’ll stick with this project through to the end.