6 kyu
Sqrt approximation
918 of 1,844riomus
Loading description...
Mathematics
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
C# restriction is not enforced properly --> 1
JS restriction is not enforced properly --> 1, 2
Python's restriction is not enforced properly --> 1, 2
Nice one, well done, congratulations.
Language: C++
Test suit missing the required header
std::vector
.The
std::sqrt
function is not disabled.Please review : C++ Fork
Headers added and
sqrt/pow
functions fixed.Kata is accomplished in c++.
This comment has been hidden.
This comment has been hidden.
n=228
)pow
or**
(hint: squaring is nothing but simple multiplication)p.s., this is not a kata issue. issues are bugs in the kata's code. you can mark this as a question next time
EDIT:Spellings
Oh ok. I see thank you. I'm a few months into coding but new to the site, so I didn't know test cases change. I'm going to review my code now.
//пишет что невидет Math.sqrt() - в vs рабботает как надо.
оно отключено тестами
This comment has been hidden.
nice kata!
test is failed for 2 and 3.
discription confusing... how about this? n=4 => (2,2)
Python translation from fork
This comment has been hidden.
This fork fixes that, and updates
Node
to18.x
.Kata fixed since site change made at https://github.com/Codewars/codewars.com/issues/1010
I can't touch the test cases since the kata already has 500 solves, but this workaround should work fine I think.
This comment has been hidden.
In JavaScript, I get the following error, even when I just put a return in the function:
should work correct for random numbers
TypeError: Math.floor is not a function...
This comment has been hidden.
Thanks for the very good kata! Though I have been very skilled since 20 years at the problem with pencil and paper, I have not implemented it in codes.
Perhaps it is amazing to test square roots of ~100,000 numbers of several billions. If you would like to make the tests harshier, long long numbers can be considered.
Hi, please approve the C++ version
C++ Translation kumited
https://www.codewars.com/kumite/57ad6fcabb9944209a0002b1
Please approve :)
'alr approved some time ago'
C#-Translation kumited!
https://www.codewars.com/kumite/57aba4a553ba339e24001632
Please check and approve!
This comment has been hidden.
Why not
Because
Math.sqrt
is disabled, as specified in the description.It seems this kata would not allow any Math methods (like ceil(), floor()). The author should give more information in the instructions.
Correct. This has been fixed.
( By disabling only
sqrt
andpow
fromMath
. )The instructions need to be more clear. I didn't know I couldn't use Math.sqrt until I looked at the comments.
Seems to be specified now. May not have been specified then.
Why can't I use Math.sqrt? The description says /nothing/ about not doing so. Needs to be added.
Added. Apparently. Don't know when.
Not a big fan of this one. If the author doesn't have the time to fix basic spelling then I just can't respect it as much as I would if it was all polished up.
There's a minor mistake in the Kata description: "range in witch lies square root "
Looks fixed
This comment has been hidden.
Suggestion: add a few test cases for computing roots of large numbers (10,000,000+). That should eliminate the most blatant brute force solutions.
There's something wrong with the random test cases. The random number is always between 0 and 1, and so the answer is always [0, 1].
Your test uses
Floor((Random() * 1000) + 1)
. This might just be a syntax that I'm not familiar with, but it doesn't work in my nodejs console, and I've never seen it before. This is what works in my console:Math.floor((Math.random() * 1000) + 1)
. Even so, the first syntax doesn't work at all for me, so I don't know how it's returning a random number between 0 and 1.because i'm removing totaly Math object (it's writen in description) floor and random functions are rewriten in Random and Floor variables. Now it's fixed (I rewrited Math.random to Floor instead of Math.floor)
I'm getting this error now when I submit code that worked before:
Quite wird, I think it's problem related to Codewars engine
@riomus, your random test cases might be more reliable if you used Test.randomNumber, which generates a random integer in the range of 0 and 100. You can review the documentation here. It doesn't go into much detail about the 0-100 thing, but it does link to the source code on GitHub (which is where I determined that figure).
@hencethus, I think it may be a problem with the codewars engine, but I haven't had any problems today. Need to go at this kata again.
Yea, @riomus, @hencethus, I'm getting the same error with Document.find.
Ok, test are now using Test.randomNumber (it is using Math.random and Math.round so quite nothing changed)
My solution should not have passed. I did not return any arrays. The tests are broken.
It should be fixed now
I realize the description doesn't mention performance, but a lot of these solutions are worst case brute force and I'm not sure the kata is really teaching them anything. Maybe should include a pointer to Wikipedia in the description to encourage people to consider implementing a more reasonable algorithm? http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
I'd imagine Newton's method should be good enough.
Ummm.... Is this out of beta? Because given my solution, this shouldn't be out of beta.
Edit: adding some info on how to make it acceptable.
For integer roots, you can use Test.expectEquals (this would be nice, but it's not necessary). For range approximation, use Test.assertSimilar (really). This will do a better job than your array_equals function and will fail cases correctly.
I would also recommend randomizing your test cases to prevent people from being able to match up to sequential solutions.
I am with jacobb on this. The array checking is broken and the static test cases make cheating too easy.
Editing disappeared, meant to say Test.assertEquals and not Test.expectEquals
Good catch guys - I've pushed this back into beta until these issues are addressed.
Should be fixed now
Test fixture has syntax error - see comment from srgrn.
Yes, thanks. It should be ok now.
weird when i try to retake it it still seems wrong
it("should work for range approximation", function () { Test.assertSimilar(sqrtApproximation(5), [2, 3])); });
should be it("should work for range approximation", function () { Test.assertSimilar(sqrtApproximation(5), [2, 3]); });
Yeah, just noticed the same :)
Thanks, now it should be ok
there is a typo in the tests attached to the kata
If You are talking about that one in "approximation" word, then it's fixed.