-
-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add exercise 'square-root' #245
Conversation
let | ||
fun recurse guess = | ||
let | ||
val estimate = (guess * (guess + 1) + radicand) div (2 * guess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide a brief description or reference for the methodology which is used to compute the square root (as a docstring)? This looks a bit like Heron's method, but possibly slightly adapted to the integer world?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment added. We implement Heron's method using integer arithmetic, rounding the estimate to the nearest natural number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sounds reasonable. I didn't rigorously check it though, the tests pass and I assume that you made sure some kind of correctness in general?
If yes I will merge it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested radicand values 1 .. 10000
My V implementation also works for 0, but that isn't important as the instructions exclude 0.
let | ||
fun recurse guess = | ||
let | ||
val estimate = (guess * (guess + 1) + radicand) div (2 * guess) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK sounds reasonable. I didn't rigorously check it though, the tests pass and I assume that you made sure some kind of correctness in general?
If yes I will merge it.
No description provided.