Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Ask yourself, if a number is divisible by
x
, then what is its remainder after the division ? ^^This comment is hidden because it contains spoiler information about the solution
1492952653 is not prime:
1492952653 = 31 × 48159763
. The problem is with your code.This Kata doesn't work for Python. In the random tests it returns that the number 1492952653 isn't prime. Is it a fail in the Kata or in my Code?
The problem is that with
Random.Shared.Next(1, int.MaxValue)
, your tests have a very high chance to be mostly meaningless: they will generate many numbers which are very easy to solve, and very few interesting numbers, which are more difficult to solve. For example, out of 30 numbers you generated, approx. 15 of them will be even numbers, which are trivial to solve.Your tests are not great, because they do not generate interesting inputs. Your solution is apparently also not great, because it's not able to solve the interesting inputs :)
Well, I have some bad news: there seems to be ~1000 tests when you hit "Attempt".
The problem is that your solution is doing more work than it has to. Your
max
condition can be improved significantly :PC#. Why does "Attempt" time out? I extended the test script to include 30 of these:
yield return new TestCaseData(Random.Shared.Next(1, int.MaxValue)).Returns(true);
and multiple test runs completed in, and I quote:
Time: 4756ms Passed: 6Failed: 30Exit Code: 1
Time: 4578ms Passed: 6Failed: 30Exit Code: 1
Time: 6446ms Passed: 8Failed: 28Exit Code: 1
Time: 9301ms Passed: 9Failed: 27Exit Code: 1
Time: 8725ms Passed: 9Failed: 27Exit Code: 1
Time: 5229ms Passed: 7Failed: 29Exit Code: 1
yet "Attempt" constantly times out at 12s. It seems like "Attempt" runs considerablly slower than merely testing.
I will skip this kata :(
Read about
sieve of eratosthenes
What does your function return for negative numbers like -3? Read the description again. Also, printing the input would help you debug your code.
First of all, your code is almost unreadable because it's all on one line. Format it properly as shown here https://docs.codewars.com/references/markdown/#code-block
Secondly, from description:
Why are you bothering with negative numbers then?
It also looks like you got some flawed logic in your
else
statement, but it's just a guess because, again, your code is unreadable right now.This comment is hidden because it contains spoiler information about the solution
In VS it works. But here no, i can't understand
This comment is hidden because it contains spoiler information about the solution
prime is not a negative number
Your code being too slow is not a kata issue. Try using a faster algorithm. Read the Note in the description about performance btw.
Loading more items...