First of all, the Babylonian square root is a Babylonian algorithm for calculating the Babylonian Square Root (duh…) of a given number, say *n*, but in a non conventional way. This algorithm consists of making a guess (i.e.: think of an approximate value to the actual square root), say *g*, then, you add *g*, to the ratio of the number and the guess, and divide that by 2.

So, this is:

And the result of this equation is the new guess.

We do this process several times and then the final guess is the result of the square root.

This is the class, without the method for calculating the square root.

So the algorithm says that we need to pick a near number to the actual square root. So I imported the Random class to pick some random number near the half of the number, because YOLO. Then I used that number as the first guess and executed the algorithm.

And here’s the final code.

And the github repository.

### Like this:

Like Loading...