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.
Yes. It's pretty improtant to create programs which give you answer on the same day you asked.
Expected complexity is a bit worse than logarithmic, but much better than linear. Linear solution will not pass, but it's very easy to come up with much more performant solution than linear.
Do not focus on the loop step, step of 2 is perfectly OK, but step of 1 would also pass the kata. More improtant is the upper bound of your loop. Try to figure out how far you need to loop, and at what point you are perfectly sure that you do not need to loop any further.
Are we really testing programming anymore?
Runtime performance is an advanced topic.
I special cased the loop increment to 2 after
a threshold and doubled the number of random number
evaluations from 30 to 60 but still times out.
Looking at primes from 1..100 shows 25 primes with
prime gap deltas of 2,4,6,8. I am not sure how to be
systematic in this effort. Is there a paper someone
can direct me to?
Richard
This is approximately logarithmic?
Good thing is that your solution is rather correct, because it returns correct answers.
Bad thing is that it's too slow, and manages to pass ~35 random tests out of 1000. You need to think how to improve performance, but it might be easier than you think. This kata does not require memoization, and your solution will pass even if it performs separate calculations for every input. You just need to figure out how high your loop should go before being certain that the number is (or is not) prime.
when you try the test, there is info "Completed in ..."
under the window where you put your code there is sample test. you can change it, for example type some big prime number instead of existing prime. you will see how long it takes when you run the test.
My solutions either run into memset (bool) space or runtime exceeded.
The straightforward wiki dfn causes runtime exceeded (attached below).
My for loop upper bound increment is i++.
Maybe it can be dynamically trimmed to avoid
visiting multiples of existing primes?
**Is that the right direction towards a solution? **
Random_Test
1 num:876527174 .. is not prime! 21 num:1577810551 .. is not prime!
2 num:1644030750 .. is not prime! 22 num:1266333403 .. is not prime!
3 num:1393969603 .. is not prime! 23 num:2132127515 .. is not prime!
4 num:1335491684 .. is not prime! 24 num:1281074547 .. is not prime!
5 num:1929713169 .. is not prime! 25 num:90046948 .. is not prime!
6 num:24193965 .. is not prime! 26 num:2068897426 .. is not prime!
7 num:49651675 .. is not prime! 27 num:1737718634 .. is not prime!
8 num:218588094 .. is not prime! 28 num:714922702 .. is not prime!
9 num:356028242 .. is not prime! 29 num:162692740 .. is not prime!
10 num:877418047 .. is not prime! 30 num:587217759 .. is not prime!
11 num:901310737 .. is not prime! 31 num:869667984 .. is not prime!
12 num:1107801141 .. is not prime! 32 num:1039219915 .. is not prime!
13 num:2099772465 .. is not prime! 33 num:83764861.. IS prime!
14 num:993022361 .. is not prime! 34 num:116153939 .. is not prime!
15 num:503688437 .. is not prime! 35 num:227227951 .. is not prime!
16 num:735156648 .. is not prime!
17 num:1089112823.. IS prime!
18 num:914354483 .. is not prime!
19 num:390465283 .. is not prime! STDERR
20 num:1819589577 .. is not prime! Execution Timed Out (12000 ms)