5 kyu
Sum of (Two) Squares
532 of 1,369boatmeme
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.
Lua translation!
So cool kata> Thanks)
Python: Returning a list of tuples would be more pythonic.
Very nice kata! The low timeout forces efficiency and adds to the challenge and fun!
true..
Node 12 should be enabled (Refer this and this for more info)
Python new test framework should be used (Refer this & this for more detail)
Ruby 3.0 should be enabled (Refer this & this for more detail)
No sample tests in CS
No random tests in CS
Test.expect
should be replaced withTest.assertDeepEquals
This comment has been hidden.
Python translation kumited -- please check and approve
Approved some time ago, would you mind updating it to latest framework if had the time, ^^ ~~
done
Needs actual example test cases (Ruby)
Added example + random tests to Ruby and JavaScript
Your description is still wrong
Zero is not positive! It is not a positive integer value - you should either update the description to say "Non-negative integer value" (both for the function argument, and the integer pairs you return) or remove the zeros from the allowed arguments and allowed integer pairs.
With the current description, these are actually wrong:
Fixed
Seems like more of a math problem than anything...
Maybe some hints as to what kinds of optimizations could be applied might have been helpful.
It isn't really a math problem; it can be solved that way but it isn't necessary to pass. Skills beyond grade school not required :)
Nice Kata ^_^ I have a suggestion, that you can change the
positive integer
in the description towhole numbers
.Alternate suggestion:
nonnegative integer
Fixed
.
"We are asking for a function to take a positive integer value"
Yet we have 0 as one of the test inputs. Zero is not a positive nor negative integer.
Fixed
Keep getting Unknown error. Though the code works fine on my computer with ruby 2.0.0
This comment has been hidden.
code is fine and even the tests are passing
try to submit again - if you still getting an error - then your code is not fine (perhaps you missed the requirements). does it make sense?
Btw, with this timeout - this kata should be at least 4 kyu
If it's timing out then you have to make your solution more efficient. Remember it's taking 2^32 - 1 as its max int. You have to pass that case and all others in 6 seconds. Maybe you have more time on your computer's compiler
This timeout thing is bugging the crap out of me, although I guess that makes it a little more fun. Does anyone know what the timeout is set to? As passsing the max number into my current solution completes in 5052.000ms (5.05s) It'd be much better if I knew what I was trying to keep it under.
Edit: I went looking into the Docs and it's 3 seconds, if anyone else is interested.
Oh, I thought it was 5 seconds... - https://github.com/Codewars/codewars-runner/blob/master/lib/config.js
I guess the Docs (http://www.codewars.com/docs/javascript-sandbox) are a little outdated then, thanks!
Anyway, if you need to speed this up, try to think of a good maximum value for one of the loop variables.
For large values, there's a little theorem from number theory that could help:
AFAIK the docs should refer to the current stable implementation while the codewars-runner config is for the beta Docker system, which has an opt-in button in your account settings.
This theorem doesn't work for this kata. Think about how to reduce number of cycles of the loop - that's helped me a lot. Before that I got interrupt (more than 6 seconds). After improvement - all tests have been completed in ~ 0.3s (<300ms)
tricky, but good kata!
any reason for
Java heap space
Getting that too.
What language, JS? Presuming so, you've tried to put too much data into one variable.
I receive
undefined method `length' for nil:NilClass
error. Since, I'm not using a length method at all, I assume this is on the testing end. Any help?I am geting the same for
reverse
NoMethodError: undefined method
reverse' for 0:Fixnum`I'm having the same problem
You say positive integer value pairs. 0 is not a positive integer...
Fixed
I wonder how to make my thing work faster. I'm good up until that 10 digit number.
Honestly, this should be 4 kyu with the code timeout. I.e. the "naive" approach I'm using doesn't work with the timeout.
Nevermind, I'm going to use that as a solution for a new kata.
Definitely not a 5 kyu kata with the timeout.
This comment has been hidden.
I got "Incorrect Answer for 0" when returning []. I also think the description is a bit misleading.
Well, the solution to 0 is definitively [0,0], so if you return an empty array, I suppose it isn't correct...
This comment has been hidden.
Would you mind adding the "positive" to "integer" already in the first description? Else I pride myself of finding an error, when you do explain it correctly later on...
I would not mind at all. Good catch.
In fact it should say non-negative integers.
Yes, because 0 is not a positive integer, but is allowed. Does one still use N0+ to describe all positive natural numbers, including 0?
Could you please make your texts failing messages more descriptive? Like "With "X" as parameter I expect to have "Y" but got "Z"" or something like that.
The problem with this is that it gives away the test cases.
So? This isn't school. People are here to learn and get better. If they're writing their code as switch statements for particular tests, that's their loss. Real test-driven development involves being able to see the tests that you're writing code for.
You don't have to give away all the test cases, we're saying they must be more descriptive, with x input, y output is expected, you have not to show what a test case is doing inside.
Great kata! And I would keep the low timeouts, forces an efficient solution
Your solution is pretty crazy...
I get
Timeout::Error: execution expired
. I have no idea how to make code more efficient. I am already memoizing squares for first item of the array so I use calculated results for the second. What else can I do?Try it now. I've increased the ruby timeout to 4 seconds which should be plenty of time.
That was my mistake, I was using an extremely inefficient algorithm. Changing my approach fixed the issue. Thanks for quick reply!
I agree. The word "unique" is misleading and the latter requirement states all that is necessary by saying the same pair cannot be listed twice. I will fix the description. Thanks for the feedback!
The description is a bit misleading. You state: "The return value should be a two dimensional array of unique, positive integer pairs in any order." Which makes me believe that they must be pairs of unique, positive integers. However, the expected result for 0 is [[0, 0]] not []. Clearly 0 and 0 are not unique. The third requirement "We will consider 5,0 and 0,5 to be equal pairs, disregarding the order. Do not list the same pair twice." clearly defines that the same pair cannot be listed twice. I would simply remove the word "unique" in the first requirement to make it more clear. But nice kata.