Closed heptalophos closed 11 months ago
Hi @heptalophos!
It works as intended from my point of view, **
is the power operator and the point of this exercise is to implement yourself an algorithm for computing the square root without built-in methods.
Otherwise you could just do floor (radicand ** 0.5)
and be done with it. Your solution is fancier, but is essentially the same.
May I show you this link? Plenty of fun algorithms to try out :)
@jiegillet Yup, but I think we forgot to mention Kernel.**
in the comment, I'm adding it here: https://github.com/exercism/website-copy/pull/2282
Thanx.
I still think though that completely blanketing out an essential arithmetical operator like (needed -for instance- at a previous point for a quite different calculation), is a bit sloppy. And no, the exponential identity is not actually essentially the same as doing `floor (radicand 0.5)`.
It is in fact included in "the plenty of fun algorithms to try out" in that link 😀
I have got the following complaint from the Analyzer:
after submitting this iteration:
As you can see, I have gone out of my way to avoid using a reference to any
:math
functions, to the point of hard-coding Euler's numbere
- which is private anyway in:math
, as it's mentioned in my comment above (at first I thought that this might have triggered the complaint 😀) - and defining an anonymous function to approximateln(x)
, so as to not use:math.ln/1
.Then I used
Kernel.floor/1
because thenat_log
approximation slightly overshoots the integer square root. Initially I thought that Analyzer didn't like it, becausefloor/1
returns a float and the@spec
demands apos_integer
so I changed the last line totrunc (e ** (0.5 * nat_log.(radicand)))
in the next iteration.And I got exactly the same response.
And then I checked The Analyzer's test-suite and found this curious assertion:
🙂