Skip to content
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

Merged
merged 2 commits into from
Dec 17, 2023
Merged

Conversation

keiravillekode
Copy link
Contributor

No description provided.

let
fun recurse guess =
let
val estimate = (guess * (guess + 1) + radicand) div (2 * guess)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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.

@rainij rainij merged commit ddb8ca1 into exercism:main Dec 17, 2023
2 checks passed
@keiravillekode keiravillekode deleted the square-root branch December 17, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants