5 kyu
Primes with Even Digits
418 of 910raulbc777
Loading description...
Strings
Data Structures
Algorithms
Mathematics
Number Theory
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.
add dynamic programming tag imo
as for 10000 in the test case is 8887 shouldn't it be 9887?
7 and 9 are odd digits, 8 is an even digit.
There are 3 8s in 8887 and 2 8s in 9887.
Since 3 > 2, you should return 8887.
As given in the question. For n = 1000, the highest prime under 1000 is 887. The highest number that has maximum no of even digit is 889..right?
889 is not a prime and the highest number with the most number of even digits is 888.
Huge Values of n (From 100000 up to 1000000) STDERR /workspace/default/tests.py:18: DeprecationWarning:
np.bool
is a deprecated alias for the builtinbool
. To silence this warning, usebool
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.bool_
here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations sieve = numpy.ones(n // 3 + (n % 6 == 2), dtype=numpy.bool)Execution Timed Out (12000 ms) Test routine failed to generate large primes:- Problem?
Updated to Python 3.11, but your solution is not sufficiently fast.
python new test framework is required. updated in this fork
Approved
So challenging that the same solution one time passed and the other not, how come?
I haven't solved the kata yet, but it is possible that the fixed tests simply do not cover all cases and random tests only sometimes cover certain cases on some of the
ATTEMPT
s but not every time...Nice Kata!
Python: even with a quick search for prime numbers, the task is output Execution Timed Out (12000 ms)
Not checking more than once if a number is prime could help. :P
[Python] Unfortunately the serious test always aborts with an error message because of the test code: /workspace/default/tests.py:7: DeprecationWarning:
np.bool
is a deprecated alias for the builtinbool
. To silence this warning, usebool
by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.bool_
here. Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations sieve = numpy.ones(n//3 + (n%6==2), dtype=numpy.bool) Traceback (most recent call last): File "/workspace/default/tests.py", line 54, in result = f_sol(n) File "/workspace/default/tests.py", line 36, in f_sol max_even_digs = max(resDict.keys()) TypeError: 'int' object is not callableupdated to Python 3.11
it has too large test cases, and it causes me a timeout errors althought my solution is right.
Your solution being too slow is hardly a kata issue.
Well, a solution must run fast enough to pass the test. That rule is the same for all Katas. You need more efficient code.
yeah but the most important thing is that the solution is true.
Solution which takes a minute, 1 minutes, or an hour to run is not "true" if it is possible to solve the problem in a second. "returns correct answer" is not the only criteria of correctness of a solution.
That may be so, but Codewars is a kind of sport. Performance katas are like a race.
That's a problem with your code, not a kata issue.
Why does it count 0 as an even numbers? The assertion for 1210 is wrong.
The digits {0,2,4,6,8} are the even digits and the digits {1,3,5,7,9} are the odd digits - that's a pretty standard definition of even/odd digits? Or maybe I do not understand your question properly?
i've just never counted 0. I know that it technically is. But i've always gone by the physical meaning of even haha
Not a kata issue.
Please review: C++ Translation
Approved +1 Thanks
D translation
Approved by someone
Good day everyone. Does anyone knows correct outputs for these inputs: 7456,_____,18647, 401822
Thank you in advance
Fun kata. Optimizing everything from determining whether a number is prime to determining how many primes is good information to have. I do wonder what the average runtime for this is though. My solution took 9 seconds the few times I ran it, and I thought I had a pretty fast algorithm.
It assertions shows the wrong input:
language?
Python.
(I guess there might be more katas with this issue)
test.it
are aftertest.assert_equals
, so the logs give the previous input. I tried to fix it but there are more issues in the way tests are organized, I renounced.fixed in latest fork
aaaaa this kata was painful, but fun. Finding the solution was easy enough, the real challenge was finding a solution that didn't make the console time out. Nice Kata
How you optimize it, it is killing me I am blocked :(
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
No matter how much I try to optimize my solution, it times out on Python. My IDE takes about 2ms. What is wrong with this ?? >:(
Just because it takes 2ms on your computer doesn't necessarily mean anything. On most online judges, the constraints are large enough to tell you if your solution is unoptimized or not.
Thank U for good kata!
Ruby:
Python:
fixed
Seems like JS random test cases still contain errors. Either that or I did something wrong, but I got lucky after a few submits.
Sweet Kata!
Hey could I get the number n at which the error occurs? Currentely I cannot recreate the error on my machine. At some random numbers I get an error, example:
Hihger Values of n (From 1000000 up to 5000000) 1048447 should equal 1288849
Unfortunately it does not tell me what n was.
Running numbers through my code bigger than the ones given always gives me the right answer. I'm kinda hung up here. I'll leave my code in a reply to this comment.
This comment has been hidden.
I really liked this kata as I thought there is no way to pass if the solution doesn't eliminate numbers which by definition cannot be primes but I see alot of solutions accepted not caring about that fact at all. So I was curious and copied a few solutions and ran them and they all timed out as expected.
Did the kata got more strict at one point?
I guess it's just an issue with the codewars server performance. I rerun my (unoptimized) code several times, and I got various results from ~4000ms to timeout (12000+ ms)
Raul I love your katas, but this is the first one I've completed without a timeout! It's a good day!
small improvements to be done:
// your code here
--># your code here
fixed
This comment has been hidden.
This comment has been hidden.
Hi Raul, your JS testcases contain some/many random test errors, like this example:
4801 is a prime and greater than 4663 (both with three even digits), but lower than your input 4808;-)
Oh thanks I'm going to check them
Hope that it's fixed now. Thanks a lot Matthias for your observation in the Javascript version. Let me know if you find everything ok.
Hi Raul, marked issue as resolved - but hard to test it at the moment (seems to me that it is ok now), since yesterday (new price model;-)) i generally get many codewars- timeouts:-)...
This comment has been hidden.
This comment has been hidden.
haha those things may happen using memoization. It happened to me here, too, twice or three times. Thanks Matthias for your solution.