6 kyu
Not prime numbers
520 of 1,551riyakayal
Loading description...
Fundamentals
Performance
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.
I really enjoyed this one! Prime numbers strike again — they never get old. Always fun to revisit them with a new twist!
Haskell:
Description says a and b will both be <= 20000 but the tests expect values beyond that.
Haskell fork that fixes that.
Approved
One more Prime numbers kata!
Another nice kata of the series on primes and performance.
so suitable by c++
Ruby version is faulty. Description says a and b will both be <= 20000 but the tests expect values beyond that.
[2222, 2223, 2225, 2227, 2232, 2233, 2235, 2252, 2253, 2255, 2257, 2272, 2275, 2277, 2322, 2323, 2325, 2327, 2332, 2335, 2337, 2352, 2353, 2355, 2372, 2373, 2375, 2522, 2523, 2525, 2527, 2532, 2533, 2535, 2537, 2552, 2553, 2555, 2572, 2573, 2575, 2577, 2722, 2723, 2725, 2727, 2732, 2733, 2735, 2737, 2752, 2755, 2757, 2772, 2773, 2775, 3222, 3223, 3225, 3227, 3232, 3233, 3235, 3237, 3252, 3255, 3272, 3273, 3275, 3277, 3322, 3325, 3327, 3332, 3333, 3335, 3337, 3352, 3353, 3355, 3357, 3372, 3375, 3377, 3522, 3523, 3525, 3532, 3535, 3537, 3552, 3553, 3555, 3572, 3573, 3575, 3577, 3722, 3723, 3725, 3732, 3735, 3737, 3752, 3753, 3755, 3757, 3772, 3773, 3775, 3777, 5222, 5223, 5225, 5232, 5235, 5252, 5253, 5255, 5257, 5272, 5275, 5277, 5322, 5325, 5327, 5332, 5335, 5337, 5352, 5353, 5355, 5357, 5372, 5373, 5375, 5377, 5522, 5523, 5525, 5532, 5533, 5535, 5537, 5552, 5553, 5555, 5572, 5575, 5577, 5722, 5723, 5725, 5727, 5732, 5733, 5735, 5752, 5753, 5755, 5757, 5772, 5773, 5775, 5777, 7222, 7223, 7225, 7227, 7232, 7233, 7235, 7252, 7255, 7257, 7272, 7273, 7275, 7277, 7322, 7323, 7325, 7327, 7332, 7335, 7337, 7352, 7353, 7355, 7357, 7372, 7373, 7375, 7377, 7522, 7525, 7527, 7532, 7533, 7535, 7552, 7553, 7555, 7557, 7572, 7575, 7722, 7725, 7732, 7733, 7735, 7737, 7752, 7755, 7772, 7773, 7775, 7777, 22222, 22223, 22225, 22227, 22232, 22233, 22235, 22237, 22252, 22253, 22255, 22257, 22272, 22275, 22322, 22323, 22325, 22327, 22332, 22333, 22335, 22337, 22352, 22353, 22355, 22357, 22372, 22373, 22375, 22377, 22522, 22523, 22525, 22527, 22532, 22533, 22535, 22537, 22552, 22553, 22555, 22557, 22572, 22575, 22577, 22722, 22723, 22725, 22732, 22733, 22735, 22737, 22752, 22753, 22755, 22757, 22772, 22773, 22775, 23222, 23223, 23225, 23232, 23233, 23235, 23237, 23252, 23253, 23255, 23257, 23272, 23273, 23275, 23277, 23322, 23323, 23325, 23332, 23335, 23337, 23352, 23353, 23355, 23372, 23373, 23375, 23377, 23522, 23523, 23525, 23527, 23532, 23533, 23535, 23552, 23553, 23555, 23572, 23573, 23575, 23577, 23722, 23723, 23725, 23727, 23732, 23733, 23735, 23737, 23752, 23755, 23757, 23772, 23775, 23777, 25222, 25223, 25225, 25227, 25232, 25233, 25235, 25252, 25255, 25257, 25272, 25273, 25275, 25277, 25322, 25323, 25325, 25327, 25332, 25333, 25335, 25337, 25352, 25353, 25355, 25372, 25375, 25377, 25522, 25525, 25527, 25532, 25533, 25535, 25552, 25553, 25555, 25557, 25572, 25573, 25575, 25722, 25723, 25725, 25727, 25732, 25735, 25737, 25752, 25753, 25755, 25757, 25772, 25773, 25775, 25777]
Fixed in this fork, re-raised for Haskell
python updated test framework
Approved
Time: 7000+ms Pretty damn bad. xD
C++ Fork with fixed issues.
Approved
Language: C++
Test suit missing the required header
std::vector
.Indeed : need to add
using namespace std;
in the C++ user solution for the tests to compile !Another example of the codesmell "using namespace ..".
Fixed
Can somebody tell me whats the input size? Description says that b <= 20000, but my IDE shows that my code can handle that in under 200ms, however Im getting timed out
In python there are 1200 random test. 200 ms per test is too slow.
This comment has been hidden.
Fixed
Basic Tests Sample Tests (5 of 5 Assertions) Random Tests Small Random Tests (200 of 200 Assertions) Big Random Tests (855 of 855 Assertions) STDERR Execution Timed Out (12000 ms)
have issue 2773 is prime number
2773 = 47 * 59
case number 3 check for solved
Language: JavaScript
Based on the test case:
a
is inclusive andb
is exclusive, but the description doesn't say anything about it.The description gives
[a,b)
, this means b is excluded, see en.wikipedia.org/wiki/Interval_(mathematics)#Terminology.c++ basic test won't compile unless you include
Attempt compiles.
Fixed
This comment has been hidden.
Haven't tested your solution, but maybe since you didnt clear your res list before you returned it, it keeps adding on values.
Not an issue. Don't use global variables.
This comment has been hidden.
Generate only all numbers with digits 2,3,5,7, instead of filtering
range(a,b)
.It can be done, but I don't know how easy it is in your language. Good luck.
Haskell translation
Please review and approve.
This question needs to increase its time limit. I have got all the variations of my anwer correct in the sample tests, but during the final attempt my answer is rejected due to the time it takes to execute, despite being absolutely correct! Or either reduce the range of data provided!
86 people have already successfully solved this Kata using JavaScript. So I would respectfully suggest that you have some optimisation to do :)
To be clearer about this: it's my experience that, when solving Kata, the final tests are often significantly more challenging than the sample tests. It's not at all uncommon to find you have code which works for the samples but doesn't work for the final tests, and to have to optimise your code or even change your approach entirely.
Also note that the description for this Kata specifically says:
Yeah, but what if i'm trying this in Python? And i'm simply trying to say that answer should not be rejected on the basis of the time it takes to get executed. I mean 12 seconds is not that much, right?
When someone authors a Kata, or translates an existing one, they provide a sample solution in the target language. This solution gets run against all the same tests as part of the submission process, and has to complete within the time limit in order for it to get published. So it's not possible to create a Kata whose correct solutions will take too long.
Oh! That is a cumbersome procedure, no doubt! Thanks for the help btw! :)
Part of the challenge of these problems is to produce code that runs within the time and resource constraints available. This is no different from being a programmer in the real world.
Some of the harder Kata on this site are difficult precisely because they require a lot of work to get them to run within the time. See for example the 7x7 skyscrapers Kata which is crazy hard for exactly this reason.
This question needs to increase its time limit. I have got all the variations of my anwer correct in the sample tests, but during the final attempt my answer is rejected due to the time it takes to execute, despite being absolutely correct! Or either reduce the range of data provided!
.
This was supposed to be a 6kyu kata but i was only rewarded two points , why?
You are a 4 kyu user, so solving a 6 kyu kata isn't worth very much to you. If you solve a 1 kyu kata then you'll get kerjillions of points!
^Is that so? I believe the kata rewards are consistent among all Kyu levels. I'm a 3 Kyu user but receive 6 points for this kata.
@riyakayal, C/C++ and Java translations available.
Haskell translation
Please review and approve.
This comment has been hidden.
Brute force will not cover all
1204
tests. Find a solution that doesn't go through each number one by one.This comment has been hidden.
Finally optimized the code enough. It was a really dumb mistake. Wow.
Javascript translation
Please review and approve.
The first test should include 222 as the final number in the list to return, but the test solution is excluding it, causing my solution to fail.
no problem. will check
The Python version is the original and it doesn't include 222. Although not in the description, the upper bound is excluded.
According to the description it looks like lower bound should be included and upper bound should not be -
[a, b)
. But your translation excludes lower bound.I did not look at the original, so I do not know which is correct.
I just tested this in the Python reference solution, which is the original (as I have already stated above).
It works. Upper bound NOT included. It helps if you check the Python set up to confirm this instead of shooting in the dark.
I am not arguing about upper bound - I agree it should not be included.
What I was trying to say is that lower bound should be included according to the description, but is not in your solution.
Agreed. Nice catch!
I have changed it. Lower bound now inclusive. No solutions were invalidated, which means that this ommission was not significant.
Mine was invalidated. :~(
;-)
Haskell translation
Please review and approve
please approve this.
Ruby translation submitted :)
STDERR: File "", line 10 test.describe("Basic Tests") ^ IndentationError: expected an indented block
?
That's an issue with your code, not the kata.
Most probably you're missing a closing bracket
)
or colon:
yup, even after RESET, i missed that commented 'pass'. All good, thanks.
The test range is not very well chosen, as there are no such numbers between
7777
and22222
...This comment has been hidden.
Not a suggestion.
This comment has been hidden.
it's not about debugging, it's about changing the way you do your computations to gain some time, now. ;)
yeah yes I know. I tried to correct ten times, but still is to long .... dam it...
Try caching an/or precalculationg some thing(s)...
This comment has been hidden.
hint: "memo"
You're not going to pass if you keep recalculating the same numbers for every test.
I suggest to use a pregenerated list of numbers for the checker function, as that would allow more time for user's solution and/or allow to check higher numbers.
no, that would "flaw" the amount of performances needed. for now, any warrior has to do at least something as performant as the internal solution. Using pregenerated numbers will give the warrior more time. And if one makes the tests harder with bigger calls, the ranking might become inconsistent.
Meaning, that's my opinion. ;)
I feel like the solution itself is already so slow that it's almost impossible to do any worse, with the exception of failing to memoize. That's literally the only requirement for this kata.
I couldn't agree more. I wonder how someone at 3 kyu can write such inefficient code... At least he could "cheat" and take one of the top voted solutions :-)
I strongly recommand the addition of the
performance
tag. Your requirements are somewhat huge, here. ;).
10 ^ 5 isn't that huge..!
no, if you have the right algo. ;) (reference solution uses half of the allowed time)
To my opinion, the problem comes from kata expected answwer: most of the time is spent by cloning an array and it is very difficult to decrease that time. If this kata gives an index and asks for the corresponding number in described sequence, then an optimized algorithm will matter!