6 kyu
Backwards Read Primes
277 of 7,430g964
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.
No random tests in Java
70207 is prime. But I got an error in typescript. Please fix this.
but it's a palindrome...
should skip polindrome numbers even if it is prime?
I think its described by the "[...] when read backwards [...] are a different prime"?
cool one
There is a problem with tests, as they don't include all correct results in the resulting list. I get more values and those additional ones also correct, so there is something wrong with tests and answers. Please fix
Could you provide an example at least? Did you read that once reversed they should be a different number? So 11 is not a valid result, neither 2, 3, 5 nor 7. If you're sure there is the problem with the tests, provide your code and the language you're working on, the problem may exist only in that one.
Отличный ката, на мой взгляд один из самых лучших. Автору огромное спасибо!!!
C#
No random tests
Method name should be
PascalCase
(Please refer to implementation of backward compatibility here )Nice!
Fun kata. The challenging part is thinking of an efficient way to check if a number is prime or not.
I got strange stuff )
70207 is skipped in expected answer, but it is a prime and reverse prime is also logically prime... or? :harold:
Check the first sentence of description. 70207 is a palindrome.
oh! thanx! I hate google translator :D
Cool Kata! I love it!
JS Node 18. (
mocha + chai
) should be enabledPython:
missing test framework and solution imports
Initial solution setup should be
return []
Ruby 3.0 should be enabled
Function name should use
snake_case
i think it"s easy, but program executing for 6 seconds
The C translation of this is quirky in at least two ways. First, it uses dynamic allocation to return a two-element struct result. C has allowed struct-returning functions since the 1970s.
Second, the limits are passed as long long integers, but the simple prime testing methods (as seen in most if not all of the published solutions) wouldn't work over more than about a billionth of that range without timing out. One solution passed all submission tests with a prime test that would loop forever on any prime greater than 2^32. So what's the point of using long long?
This comment has been hidden.
Is 109561 prime?
I am having a problem with comparing program results. My program returns [70000,70300] ==[70001, 70009,70061, 70079,70121, 70141,70163, 70207,70241] Which should be a correct answer! But the kata program returns [70000,70300] ==[70001, 70009,70061, 70079,70121, 70141,70163,70241] 70207 should be and is a prime number!!! pls fix this bug, so i van succesfuly pass this kata
Thank you for your time!
70207 is a palindrome.
OHhh sorry, i didnt even notice that. Thank you so much for helping <3
I had the same issue at first, being confused by the first sentence of instructions "This rules out primes which are palindromes." Since 70207 is a palindrome. So I saw in tests that numbers needed to be different but maybe this could be clarified ?
It is already clarified in the previous sentence:
I would love to see test sample with more difference between start and stop, so that optimisation worth it instead of going one by one. But then maybe would it be harder than 6kyu ?
My solutions passes with keeping i if i in {2,3,5,7,11} which shouldn't !
I think tests need to be edited with some start<=11 to avoid this. (I tested in Python)
I don't understand your post. Please could you be clearer, maybe with an example?
Understood when I saw your first solution. Added a test.
This comment has been hidden.
I am getting only this test case wrong: [1095047, 1095209, 1095319] should equal [1095047, 1095209, 1095319, 1095403], can anybody help or explain? I don't understand.
Language? What is the input?
The language is Python and the input is start = 1095000 and stop = 1095403.
means you returned [1095047, 1095209, 1095319] and expected result was [1095047, 1095209, 1095319, 1095403] (usual return form of a failed test in Python).
Yes, I was trying to ask if there was anything different in that case causing only that one to fail, or whether anybody was having the same problem, thank you anyway.
This comment has been hidden.
Hello,
In my opinion the basic example is wrong. For input BackwardsPrime(2, 100) the valid (accepted) result should be [2 3 5 7 11 13 17 31 37 71 73 79 97]
Regards,
FYI: I am doing it in Golang.
Check the description again:
2, 3, 5, 7, and 11 aren't valid.
Caught std::exception, what(): std::bad_alloc why?????? whats wrong with me????????????????
It's difficult to tell without seeing your code, but my guess would be that in some place you try to allocate a very large array or vector, or an array/vector of negative size.
Well defined kata.
This comment has been hidden.
Not a kata issue, rather a question. Look at the top of the page: 463 people passed the C++ kata. BTW format your code, it is difficult to read yours...
This comment has been hidden.
About the format, read this: https://docs.codewars.com/training/troubleshooting#post-discourse
Someone tried to complete this kata in Bash? O_o
My code looks pretty efficient, but Bash isn't supposed to compute LARGE prime numbers - it's pretty slow for such tasks. My solution fails on 5'th basic test because of timeout.
For 6 kyu kata I need to implement some clever algorithm to check on various prime numbers properties, huh?
This comment has been hidden.
6 kyu... Nice kata, but it's not 6 kuy. This was hard, imho.
This comment has been hidden.
you have to handle values up to 700_000_000, that's why your code is timing out.
=> you'll have to change your approach
This comment has been hidden.
nice kata!
Thanks!
I get this when i try to test the algorithm :
./src/test/java/BackWardsPrimeTest.java:9: error: cannot find symbol assertEquals("13 17 31 37 71 73 79 97", BackWardsPrime.backwardsPrime(1, 100)); ^ symbol: method backwardsPrime(int,int) location: class BackWardsPrime ./src/test/java/BackWardsPrimeTest.java:13: error: cannot find symbol assertEquals("9923 9931 9941 9967", BackWardsPrime.backwardsPrime(9900, 10000)); ^ symbol: method backwardsPrime(int,int) location: class BackWardsPrime 2 errors
even tho it works just fine when i excute the code in my IDE .
Where is your fubction "backwardsPrime"?
yeah, 70207 is a prime. the test case is not correct
Yeah, and it's not a valid Backwards Read Prime by definition:
The tests are ok.
This comment has been hidden.
(This rules out primes which are palindromes.). You just need to add one more condition check
Somehow I didn't read it, much thanks !!
can anyone explain this to me? expected [ 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 361, 377, 389, 391 ] to deeply equal [ 107, 113, 149, 157, 167, 179, 199, 311, 337, 347, 359, 389 ]
391 is not a prime number.
thank you, i solved it
This comment has been hidden.
There are two stages of testing:
TEST
will run your code against the sample tests,ATTEMPT
will run your code against additional tests, including random tests. So, your code may pass the first set of tests, but if it times out, it is not efficient enought to pass the second set.Your code is probably too slow.
This comment has been hidden.
My Elixir solution is timing out, but when I run the same tests at my computer it finishes in 0,236 seconds. When I click "test" it passes, but when I try to "atempt", it times out. ):
There are several tests when you click Attempt, how can you know if your code is efficient enough to pass them all? Probably it isn't and that's why you get the timeout.
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Timing out is not a kata issue. You have to try and make it more efficient.
Sorry for being so stupid, imediately after commenting this nonsense I saw that that were tests bigger in the "attemp". I just used square root to decrease the range of iteration and now it works. Sorry and thanks (:
nearly fith a second is a lot of time
Someone needs to – somehow – install/enable gmp_prob_prime for PHP.
hahaha, nope
This comment has been hidden.
7000 is not a prime number. It has to be a different prime in both ways.
but 7000 is not
This comment has been hidden.
If you know wichs are the primes number, then I don't know is this answer has sense for you.
this kata needs range restriction!
Again, in R, it is highly inappropriate to return
NULL
when you have an empty result. This should be fixed as it goes against best practices for the language, making this kata grossly defective.Again, sorry. I now know you are a R-specialist but it is too late to change something. If I tanslate anew to R maybe I will take your position into account.
Thanks, I started following you so I could see if/when you post something new.
This comment has been hidden.
me too! i think this kata needs more restriction in range. even best solutions has problem in (0, long.max)
This comment has been hidden.
You write in the first few lines:
if (n <= 3) return n > 1;
but 5 and 7 are primes so if n%5 === 0 and n is 5 it should return it is a prime but returns false in your code..
Good day! I can't solve it the reason is I don't know how typedef struct Data works I don't know how to return the value without error, could you please help me. It passes first test but then next cases are not. I'm using C lang It always say
Caught unexpected signal: 6
By the way I've rewritten the code by not using typedef struct so that I'll know if my codes are in fault but it passes all the sample tests. Thanks in advance!
Isnt 11 is Backward Read Prime ? Because 11 from both sides gives 11 and 11 is prime, or do i something missing ? We shouldnt use the one which same from back and front side ?
In this kata, 11 is not a backward read prime. It needs to be different prime from original prime.
From the kata description.
Okay sorry, thank you :)
The boilerplate function name is not corrected to snake_case yet.
Fixed
Thanks!
Wow this kata is too good to be just in 6 kyu :D
I suggest to correct the data type from "long" to "int" (to save beginners from their hours of confusion).
Or to at least start with some propper testing:
[Test] public void Test22() {
[Test] public void Test23() {
Maybe description should point out that palindrome prime numbers dont count as backwards read primes. Otherwise they also should be calculated
It's already there.
Sure thing, my bad, sorry!
All I know is this is definitely too hard to be Kata 6... (JS)
The issue below is still present.
Modification done though it was not worth it:-)
The function name should be in snake_case in Python.
I don't want to invalidate all passed solutions: "mixedCase is allowed to retain backwards compatibility".
Then fix it without invalidating the solutions?
How?
py, timeout eror, I think it's serverse's problem because I can't think of a way to optimize my code.
That's your problem.
try breaking your loop
This comment has been hidden.
It is a question, not an issue. Please, before posting issues look at the top of the page to see how many guys passed the kata in your language, if the number is big enough chances are that there is a problem in your code. Cheers.
Try count prime number till sqrt (num)
for (long i = 2; i <= sqrt(num); i++)
Thank you both for the feedback. Appreciate it.
This comment has been hidden.
Your solution does not check this requirement
php has timeout error, Basic tests have been passed :(
Expected: equal to 70001 70009 70061 70079 70121 70141 70163 70241 Actual: 70001 70009 70061 70079 70121 70141 70163 70207 70241
70207 is a prime AND Backwards Read Prime
70207 is a prime AND Backwards Read Prime
No, it is not.
Sorry, my bad. You are correct, thank you.
read the requirements
[C] I have trouble with the kata ,The first test result is [7027, 7043, 7057] and im receiving the following response "Error. Expected 7027, 7043, 7057 but got 9, 4202078, 7057" I can't seem to understand the problem with my code - I have double checked the data that is stored in the array before sending it and it's [7027, 7043, 7057]
For input, (70000, 70245) : 70001 70009 70061 70079 70121 70141 70163 70241 I got primes => 70001,70009,70061,70079,70121,70141,70163,70207,70241
It failed because 70207 is not in solution list but it a backward prime as well as lie in range. Test cases are not correct. Can anyone explain me why 70207 is not a backward prime.
just "RTFM"? x)
My solution using Bash passes sample tests successfully, but when making an "Attempt" it returns "Execution Timed Out". Are tests there so heavy?
This comment has been hidden.
Why does the author exclude (backwards) prime numbers such as 2, 3, 5, 7, 11? For 1..100 the answer should be 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, 97.
Description says:
2, 3, 5, 7, 11 are palindromes.
It's better in your case to post a question rather than an issue. Cheers.
Exit Code: 1 Test Results: SolutionTest STDERR main.swift:75:41: warning: 'characters' is deprecated: Please use String or Substring directly return Int(String(String(n).characters.reversed()))! ^
Execution Timed Out (12000 ms)
Working fine on Playground though.
Timing out is not a kata issue. You could have seen at the top of the page that 107 guys passed the Swift translation. Cheers.
Why is it showing "characters' is deprecated"? I am not using it in my solution.
SCALA: I'm new in scala, I've done some test on worksheet and my result seems to be right. I don't know how Scalatest assertion work but I have the folowing error.
assert( Solution.backwardsPrime(st, nd) == "70001,70009,70061,70079,70121,70141,70163,70241", s"\nsol: (${st}, ${nd}) should be 70001 70009 70061 70079 70121 70141 70163 70241" )
Test Failed "...0121,70141,70163,702[07,702]41" did not equal "...0121,70141,70163,702[]41"
I don't understand the "[07,702]" and the "[]" part. When I print my result I have res3: String = 70001,70009,70061,70079,70121,70141,70163,70241
The
[]
shows where the results differ.No, you get:
...0121,70141,70163,70207,70241
. Print your result and you will see. Cheers.PHP. Why function gmp_prob_prime is undefined?
Not a problem of the kata... I suppose CW version of PHP doesn't have it.
Ruby fails for me when I try to
require 'prime'
read the description...?
No random tests in Python (at least).
Duplicate issue (please see below).
test - 6: my result [1095047, 1095209, 1095319] should equal [1095047, 1095209, 1095319, 1095403] (difference my code does not return 1095403), but in other test it passed.
test - 6: my result [1095047, 1095209, 1095319] should equal [1095047, 1095209, 1095319, 1095403] (difference my code does not return 1095403), but in other test it passed.
Could you please give a hint? I'm trying since yesterday and I can't get closer to the solution.
Incorrect test result using Java, my code gives proper output.
Great Kata, thank you!
Thanks!
This comment has been hidden.
This comment has been hidden.
I tried and I thought it worked but maybe it doesn't work. Could you have a look at the preloaded section?
This comment has been hidden.
Will do, thanks once more!
This comment has been hidden.
Sorry to make you waste your time!
It is a suggestion, not an issue. Moreover for a 6kyu I think that the tested range is enough.
In random tests I have result:
Expected: [1095047, 1095209, 1095319, 1095403], instead got: [1095047, 1095209, 1095319]
but I added
Test.assert_equals(backwardsPrime(1095000, 1095430), [1095047, 1095209, 1095319, 1095403])
to sample test and it's green:
Test Passed: Value == [1095047, 1095209, 1095319, 1095403]
Lunguage: Ruby
I think my solution should pass the test
Expected: [1095047, 1095209, 1095319, 1095403], instead got: [1095047, 1095209, 1095319]
means that you returned[1095047, 1095209, 1095319]
and not[1095047, 1095209, 1095319, 1095403]
.Yes, I see but the same code and the same test written in sample tests returned [1095047, 1095209, 1095319, 1095403] What's the difference? Why I can't pass random tests if the same test passed in sample tests? UPD: it was my fail with range, it's ok, thanks
Just wondering if you check the upper bound of the range? For example, for range [1095047, 1095403], did you check 1095047 <= n < 1095403 or 1095047 <= n <= 1095403?
Yes, I checked
[C++] Hello guys, could anyone explain to me, please, why it says the answer is wrong when I get the same exact thing as the solution?
perhaps whitespace at the end of the result?
Try running the trim() function
NASM Translation Kumited - please accept :D
'alr approved some time ago'
[Python, Ruby] Needs random test cases
[JS] Needs random test cases
Kata translation written by GaurangTandon (he left CW in 2017) very long ago (more than 3 years) when random tests were uncommon and approved by jhoffner himself. Nevertheless to please you I added random tests. PS: do you want to replace Voile?:-)
Not sure what you mean by that but ATM I'm hardly at the same level as @Voile (though I'd like to be one day) ;)
This comment has been hidden.
I tried a few solutions and they worked fine. Your solution works fine too on my PC if the given test is the only one. If there were problems not so many guys would have passed the Python (or the C) kata. Edit: you should change your function "is_prime".
in test case backWardsPrime2, 70207 is not a prime?
Did you read the description?
This comment has been hidden.
It's a question, not an issue.
Apologies! You're right. Thank you.
This code failed the first sample test. why?
Not an issue.
You failed 3 tests, so there are 3 failed tests shown. Nothing wrong.
It's the opposite, with that code you'll see Failed 3 (of 4 tests), but for some reason XCTest doesn't show Passed 1, instead it shows Passed 0. Try commenting the tests 2 to 4 and you'll see Passed 1.
thanks!
This comment has been hidden.
OP solved it, closing
In this kata ("Backwards Read Primes") I have received different results:
I am using C language, but I think it is not important.
Tests are the same in all languages. As you could see at the top of the page 1675 guys passed the kata (44 in C), so there are no errors in the tests. You should note that 70207 and 70507 are palindromes... PS: issues are for errors in kata not for error in your code, sorry for that. Cheers!
Yes, you are right! I forgot about palindromic numbers =)
Now I have passed all of the tests. Thanks!
This comment has been hidden.
I'm not quite sure how to to report this, but this kata is basically the same as https://www.codewars.com/kata/emirps
Look at the bottom of the two pages. Mine was done "April 24 2015, the other "August 27 2015" so post this remark at https://www.codewars.com/kata/emirps.
They're not really the same. emirps is a lot stricter performance wise.
R translation has no sample test cases (just the dummy "example" that prepopulates the field when you start a translation).
Sorry for the inconvenience. It seems that I have forgotten:-( Fixed. Thanks!
Enjoyed the kata, by the way. I really overshot the mark on my solution thinking you were going to test very large ranges (not just very large numbers)! I could have just printed to see your test cases, but instead I just kept trying to optimize a nonoptimal solution. When I get another minute I'll have to refactor and create a more sane solution.
Thanks for your post.
This comment has been hidden.
Don't put an issue to the kata when you time out. It's not the fault of the kata: your code is too slow or it can happen that the servers are too busy.
I am having the following issue: Expected: equal to 70001 70009 70061 70079 70121 70141 70163 70241 Actual: 70001 70009 70061 70079 70121 70141 70163 70241
Both are equal, what is the problem?
I don't know, maybe a CW problem. 140 guys passed the C++ kata. I just tried a few solutions and had no problem. Maybe some white spaces somewhere. It is difficult to see the multiple white spaces at CW.
I'm trying to tackle this in Swift. I've got a function that passess all the test cases, but for the life of me I can't get it down below 8000ms. I feel like I'm missing something obvious that would allow me to refactor to go faster. Any hints would be appreciated?
This comment has been hidden.
When you post solutions, mark them as "Spoiler", please!
I don't understand the last example in the description: "backwardsPrime(9900, 10000) => [9923, 9931, 9941, 9967]"
Reversing 9923 gives 3299 which is not within the given range. Same for the rest.
What am I missing here?
Reversing 9923 gives 3299 which is prime, so 9923 when read backwards is prime (it doesn't need to be in the range (9900, 10000)).
ah, now I get it. Cheers!
Expected: '[70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241]', instead got: '[70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241]' Expected: '[70489, 70529, 70573, 70589]', instead got: '[70489, 70507, 70529, 70573, 70589]'
both my returns were correct, pls fix your test cases
Backwards Read Primes are primes that when read backwards [...] are a different prime. (This rules out primes which are palindromes.)
It's so weried, I got the same answer as expected for test case, but it told me wrong.
However, I just ignored the test case and submit the solution, it passed all the test cases.
Corrected. It should have "Test.assertSimilar..." instead of "Tests.assertEqual...". Thanks!
Say no to IntStream
[109537, 109561, 109579, 109583, 109609, 109663] should equal [109537, 109579, 109583, 109609, 109663]
Isn't 109561 a prime number for which the reverse 165901 also a prime?
Please help
Hey guys, I'm passing the test but I'm always getting this:
I'm using C
I am getting this: Expected: [9923, 9931, 9941, 9967], instead got: [9923, 9931, 9941, 9967]
What's wrong here? (Using JS)
Passed all tests, but CW kept timing out when I tried to submit. Took me longer to refactor my code than it did to write it in the first place. Shaved off a few seconds here and there, cursing you at every turn...until I managed to sneak it under the wire and realised that it was a good lesson in code efficiency. So thanks for that...and apologies for the bad language albeit unheard.
Yup, I think this kata's whole point was code efficiency.
Expected: [70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241] instead got: [70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241]
70207 is a prime number according to [http://www.mathsisfun.com/numbers/prime-number-lists.html] Also it is a numeric palindrome. So my solution should pass the test...
(I'm using Ruby)
Read the two posts below from @vad_1000. We DON't want palindromic numbers:-(
Uhh I overlooked that "different" part. Sorry for that!
So don't post an issue unless you have read the description, you have read at least a few other posts, you are sure of your code:-)
Thank you very much. I am blind.
I think that something wrong with base test and random tests Time: 352ms Passed: 0 Failed: 1 Test Results: Expected: [9923, 9931, 9941, 9967], instead got: [9923, 9931, 9941, 9967]. What's wrong? Expected: '[70489, 70529, 70573, 70589]', instead got: '[70489, 70507, 70529, 70573, 70589]' What's about 70507?. This is a prime as well as a backwards.
The description says:
70507 is a palindrome.
This comment has been hidden.
I'm using C++. My code passed the example test. But when I run suite it comes to "Caught unknown exception". However, there is no error when I run the code on my computer. Here is the log: ****************** backwardsPrime ✘ Caught unknown exception
I am sorry but the kata itself is for nothing in that. 53 guys (see top of the page) passed the kata with C++, I just tried a few different solutions and all worked fine. Maybe you should try again. Maybe you could verify your code again: when you run your code on your computer you don't have the whole series of tests. Try to print the input to see what happens and where.
I have the same issue. Do you know how to fix it?
When I run my code on my computer i am able to return the answer, however it keeps terminating the process on here for taking too long
It is not an "issue" of the kata but a problem in your code. Try to optimize it so it runs faster. You could see at the top of the page that 119 guys passed the Python kata, so...
I'm kinda confused. i have optimized the prime checker using Miller-Rabin and others but it still terminates. As i said, it runs perfectly fine on my computer but its just on here
You don't need sophisticated prime checkers...
As many others i got the "over 8000ms" error message. Problem is it executes under 2.5 seconds locally in VisualStudio, does this mean that the website is running slow right now, or that is way slower than Visual Studio? Thanks.
I think there is something wrong with the tests, even though on my local system i get the correct results (array with solution) i keep getting a 'Uninitialized string offset: 4' error on the first test.
Even when i change the call to revTest to ($a, $a) which should definately be equal and correct, i get 'Uninitialized string offset: 5'
Are you sure of your code before posting an issue? I just tried PHP and everything works fine but sometimes CW PHP is very slow or even not working. Moreover there are no strings here.
I think I am running into a submission error. When I submit, i get: Test Results: ✔ Test Passed
✘ [7027, 7043, 7057, 7027, 7043, 7057, 7027, 7043, 7057, 7027, 7043, 7057, 70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241] should equal [70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241]
however, when I run a test on my local machine : print backwardsPrime(70000, 70245) I get :[70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241] I am assuming that is the proer range for the first test once you have submitted the code, but as I cannot see it I was not sure ad just guessed. Any ideas if it is a CW thing, or if I am just mising something in my local copy. Thank you!
CW is working, everything runs fine for me at least. This issue isn't the kind of error that would be caused by a CW issue anyway. Something to remember is that if you are running your local machine code in your browser then you are not using the same JS engine. Chrome for example doesn't have a stable sort.
Please which language? I can't understand how you can get numbers smaller than
70000
when the range is70000...70245
.hahahah, sorry everyone, I figured it out, silly oversight on my part, thank you!
Not really funny:-)
This comment has been hidden.
Expected and got are the same,aren't they? It is not a problem of the kata, it is a Codewars problem as it happens a lot these days. You can report it as a bug. Many CW passed the kata and the tests are th same in all languages. Anyway you succeeded, good:-) I answer late but I have just been notified.
What's about
727
. This is a prime and a backwards a prime, too! In C# test it's not included in solution outputs.The description mentions that palindromes are not allowed.
OOOOOk, my bad ^^. I should have read the description more careful...
I've had the same problem. :D
This comment has been hidden.
I am getting "Process was terminated. It took longer than 10000ms to complete" message while submitting the answers. Is there anyway i can save this kata and solution and submit it while code wars has less traffic or something?
Which language? I don't know exactly, I think your kata will be kept. Anyway if you got
"Process was terminated. It took longer than 10000ms to complete"
it is because your algorithm is too slow!-(, it's not because CW was too busy. PS: it's not an issue of the kata, it's an issue for yourself.In Java, tests 4, 8, and 17 have space characters at the end of their strings, and so pass with an extra space at the end of the string. All other strings require no space at the end to pass the test. Can this be fixed so that the test can be passed with a uniform format?
There are no extra spaces at the end of the expected strings in tests 4, 8, 17. Where did you see that?
When submitting, I passed all tests except for those (4,8,17). While attempting to figure out the problem, I submitted the same strings but each with a extra space at the end. I then failed all the previously passed tests, but passed 4,8, and 17. Perhaps there is something I am missing, but it passed the tests for strings submitted with an extra space for those tests.
Edit: I realized I hadn't taken into account an edge case. Thanks for replying!
Thanks for the feedback!
I have the same problem, could you explain what you meant by "edge case"? I'd love to do it correctly than to hard-code the answer for the cases that fail.
EDIT: NEVERMIND, the moment I clicked send I realized what may be the case.
using c#. it's solved but when i submitted it. => ahh... Process was terminated. It took longer than 6000ms to complete.
Also solved it with C# but used Parallel.For(start, end+1, i => { .... }); that pushed it below 6000ms
OK ill try tHanks
I like the problem,it's cool. I think my code works, tested it with upto 100k in my pc but, everytime I submitted, "Process was terminated. It took longer than 6000ms to complete" compute-intensive problem such as finding fib number or prime, if you put up too large a number for the test, the server may not be able to handle it within a reasonable time frame.
Which language? The timing is sufficient but when codewars is too busy, it can time-out.
Favorite kata so far. Not a fan of the interface presented by the backwardsPrime method (string?!), but the puzzle was cool nonetheless.
Thanks for the feedback.
Please include in the description that
start
andend
are both inclusive. I just published a JS translation. Accept it if you like please!I modified the description and then went for approving your translation but it's impossible: "Translation can't be approved, first merge recent changes". I should have approved first... I don't know what to do now. You should have done the change yourself:-( Maybe you have first to re-edit your JS translation along the whole process, try it... I'll keep you informed!
I cannot publish a new translation because the first one already exists at http://www.codewars.com/kata/backwards-read-primes/translations . Do you have a merge/approve button there?
I only have "Approve", "Reject", "Fork". When I "Approve" it's said that I can't because recent changes must be merged first. Can't you re-edit your translation? If not, maybe I must reject it and then you will be able to write and publish a new one and then I will approve the new one? I don't know which process we must follow!
Guarang should be able to fork his own translation. An edit will preserve the current situation.
Thank you @bkaes. I forked my translation - http://www.codewars.com/kumite/5559ff1cd1ef41827800014c?sel=555b061241a7ca83270001cf
Translation approved. Thanks once more to @bkaes and also to @GaurangTandon for the translation.
Glad to be of help!
There should be random tests in Haskell instead of the third series. Feel free to leave a comment if you need help with those, although it could take a while till I answer.
Yes, I would need help (see my post below your "Issue") but I know you have not much time.
I can edit your tests tomorrow (probably).
At last I installed "Hspec" with Cabal and I copied your example in a file but I got lots of errors: (bckprimenew.hs is the file where I copied your example):
You master Haskell, ... I don't:-(
Whoops. Change the type of
testBackwardsPrime
totestBackwardsPrime :: Integer -> Integer -> [Integer] -> SpecWith (Arg Expectation)
. I usually write onlyExpectation
operators, not specs, sorry. Alternatively you should be able to remove the type completely.Thanks! Work at home on my computer but not in Codewars. I modified the tests and when I "validate" I get:
About the random tests:
Note that the reference solution must be really fast if you want to use greater numbers, since QuickCheck will generate 100 tests.
Great! Works at home (random tests too!) but not in Codewars:-( See post above with errors in Codewars.
Just remove the type of
testBackwardsPrime
. GHC should figure it out. You probably need to import other modules, and I'm not sure whereSpecWith
is exported (and which version of hspec is used on Codewars).I removed the type and at last it works! Wow! There are 17 tests and I don't put the random tests on Codewars, I am afraid it tooks too long. Do you think I need the random tests too?
That's why I've presented a version that uses only ranges within [1..1000]. Depending on your reference solution one could scale that up to 10000 even. If you use random tests, I would suggest you to drop some of the current static tests.
The Haskell tests aren't really idiomatic hspec tests:
describe "..."
should use the function's name, andit "..."
should use something like"should <do something>"
, e.g.Why? Because it will lead to the following output:
That can be read as "backwardsPrime should work for some examples", "backwardsPrime should only return numbers in the range" and so on. "nth series" on the other hand has no meaning.
However, Haskell being Haskell, your current tests would be much better if they provide additional context:
This will lead to the following output:
which makes it obvious what parameters have been used for the test, whereas your current tests don't tell the user what parameters where used.
Also, the
HUnit
import isn't necessary.Slightly off-topic: I should probably write a "Codewars.com Haskell test guidelines" wiki entry, as soon as I got enough sleep.
I understand (more or less vaguely:-( what you are saying. The "printf" would be very useful, though in many languages we only have "Expected" and "Got" but no infos on the data that are tested. I tried clumsily to imitate some of your Haskall tests but it's not that easy... First I tried to install HSpec directly and I had lots of non satisfied dependancies, maybe I should have used Cabal? So I can only test my tests inside Codewars. That is not very satisfactory. For the first time perhaps you could edit my tests (only a few tests) so I could have a real model? I know you have lots of work! I thank you for your advice, nevertheless you are fast with "Issue":-) PS: I corrected the "blockquote" in "Buying a car", did you see it?
Better messages are better. Yeah, that's a tautology, but if you would use BDD in your own programs, you would like to know what went wrong. Note that I usually also don't use this kind of style, but that's mostly due to the same public and hidden static tests, and the rest due to QuickCheck.
The
Codewars.Kata.…
style makes that kind of obvious ;). Others usually dropCodewars.Kata
. Feel free to use another prefix.Err, I've used hspec only on Windows together with
cabal sandbox
:But actually I'm writing all tests in Codewars, since I want to use the same environment.
Now seems all to be in order.
Hi, during submitting, I've encountered an error: [70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241] should equal [70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241]
As for me, it seems, that your algorithm is missing 70207 value. Is that possible?
Not possible I miss something:-) Read again the description, "70207" is palindromic!
Dammit, my fault. Thanks.
This comment has been hidden.
I, unfortunately, written "... the second one being greater or equal to the first one" but I had said "...when read backwards in base 10 (from right to left) are a different prime. (This rules out primes which are palindroms.)" so I should have said ""... the second one being greater than the first one" since it has to be different. The examples should make this clear (?): 13 and 31 fit the description but not 11 and 11. In fact which is strictly greater or strictly lower doesn't matter, I must have thought to the natural order in which prime numbers appear... I will fix the last sentence in the description and I consider that the "issue" is resolved. If you don't think so, please tell me. Thanks for your point.
This comment has been hidden.
Try without Eratosthenes' sieve.
Edit: Well, one should heed the hints one gets...
thanks
Hmm! Something wrong somewhere:-)
Type in the kata description,
egal
instead ofequal
.Fixed, thanks!
There's a typo in Python starting solution,
nd
instead ofend
.It's not a typo, I choose nd instead of end in each language to avoid confusion with a maybe reserved word... Does it cause any problem?
Well, no. :)
I was mildly confused by the usage of "nd" as well. May I suggest using "stop", "final", "terminal", "limit", "endpoint" or something similar?
+1 for stop.
"stop" agreed! Thanks.