6 kyu

Backwards Read Primes

277 of 7,430g964
Description
Loading description...
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • ejini战神 Avatar

    No random tests in Java

  • gqueen Avatar

    70207 is prime. But I got an error in typescript. Please fix this.

  • Ner0k1ch1 Avatar

    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

  • Egor318 Avatar

    Отличный ката, на мой взгляд один из самых лучших. Автору огромное спасибо!!!

  • ejini战神 Avatar

    C#

    • No random tests

    • Method name should be PascalCase (Please refer to implementation of backward compatibility here )

  • cmorris Avatar

    Fun kata. The challenging part is thinking of an efficient way to check if a number is prime or not.

  • mo.mo. Avatar

    I got strange stuff )

    expected [ 70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241 ] to deeply equal [ 70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241 ]
    

    70207 is skipped in expected answer, but it is a prime and reverse prime is also logically prime... or? :harold:

  • ejini战神 Avatar
    • Description should be language-agnostic (Remove function name)
  • ejini战神 Avatar

    JS Node 18. (mocha + chai) should be enabled

  • ejini战神 Avatar

    Python:

    • missing test framework and solution imports

    • Initial solution setup should be return []

  • ejini战神 Avatar
    • Ruby 3.0 should be enabled

    • Function name should use snake_case

  • Babs1987 Avatar

    i think it"s easy, but program executing for 6 seconds

  • Husoski Avatar

    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?

  • RomainChnrd Avatar

    This comment has been hidden.

  • Road_to_FRI Avatar

    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!

  • Lili36 Avatar

    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 ?

  • Lili36 Avatar

    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)

  • user1430804 Avatar

    This comment has been hidden.

  • kakasuarez Avatar

    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.

  • user3434370 Avatar

    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.

  • smyhwlx Avatar

    Caught std::exception, what(): std::bad_alloc why?????? whats wrong with me????????????????

  • mvrozanti Avatar

    Well defined kata.

  • F1ameAlchemist Avatar

    This comment has been hidden.

  • kee-reel Avatar

    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?

  • DenisLopatin Avatar

    6 kyu... Nice kata, but it's not 6 kuy. This was hard, imho.

  • kmilewczyk96 Avatar

    This comment has been hidden.

  • RNOH Avatar

    nice kata!

  • ouhell Avatar

    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 .

  • subarudad Avatar

    yeah, 70207 is a prime. the test case is not correct

  • ExterGr Avatar

    This comment has been hidden.

  • kue_pancake Avatar

    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 ]

  • Andrey Verbovskiy Avatar

    This comment has been hidden.

  • Earth Eagle Avatar

    This comment has been hidden.

  • lucassperez Avatar

    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. ):

  • Sutherland Avatar

    Someone needs to – somehow – install/enable gmp_prob_prime for PHP.

  • Anther Avatar

    This comment has been hidden.

  • Ze-Marcos Avatar

    This comment has been hidden.

  • raveneer Avatar

    this kata needs range restriction!

  • elmstedt Avatar

    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.

  • multitudes Avatar

    This comment has been hidden.

  • Rauluco Avatar

    This comment has been hidden.

  • EmperorMigx Avatar

    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!

  • AvramenkoArtem Avatar

    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 ?

  • WestwardLand968 Avatar

    The boilerplate function name is not corrected to snake_case yet.

  • Coldsewoo Avatar

    Wow this kata is too good to be just in 6 kyu :D

  • Blek Jil Avatar

    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() {

      Assert.AreEqual("3101202331", BackWardsPrime.backwardsPrime(3101202303, 3101202333));
        }
        
    

    [Test] public void Test23() {

      Assert.AreEqual("10003101202459", BackWardsPrime.backwardsPrime(10003101202303, 10003101202500));
        }
    
  • ander.urrutia Avatar

    Maybe description should point out that palindrome prime numbers dont count as backwards read primes. Otherwise they also should be calculated

  • brknbakis Avatar

    All I know is this is definitely too hard to be Kata 6... (JS)

  • FArekkusu Avatar

    The issue below is still present.

  • FArekkusu Avatar

    The function name should be in snake_case in Python.

  • anri_hey Avatar

    py, timeout eror, I think it's serverse's problem because I can't think of a way to optimize my code.

  • niahaarz Avatar

    This comment has been hidden.

  • Shwethar26 Avatar

    This comment has been hidden.

  • Viktorminator Avatar

    php has timeout error, Basic tests have been passed :(

  • yordanovevgeni Avatar

    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

  • glebtc Avatar

    [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]

  • mahesh2492 Avatar

    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.

  • PatrickBro Avatar

    My solution using Bash passes sample tests successfully, but when making an "Attempt" it returns "Execution Timed Out". Are tests there so heavy?

  • kmacdonell60 Avatar

    This comment has been hidden.

  • evgeni-nabokov Avatar

    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.

  • umangbista2 Avatar

    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.

  • srazafimamy Avatar

    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

  • PanKotsky Avatar

    PHP. Why function gmp_prob_prime is undefined?

  • jebreen Avatar

    Ruby fails for me when I try to

    require 'prime'

  • FArekkusu Avatar

    No random tests in Python (at least).

  • Mboburjon Avatar

    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.

  • Mboburjon Avatar

    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.

  • juanignacio Avatar

    Could you please give a hint? I'm trying since yesterday and I can't get closer to the solution.

  • psychsane Avatar

    Incorrect test result using Java, my code gives proper output.

  • TeaJunk Avatar

    Great Kata, thank you!

  • keenan560 Avatar

    This comment has been hidden.

  • anter69 Avatar

    This comment has been hidden.

  • Bruinbrood Avatar

    This comment has been hidden.

  • eionidi Avatar

    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

  • BasedCharpentier Avatar

    [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?

  • donaldsebleung Avatar

    NASM Translation Kumited - please accept :D

  • donaldsebleung Avatar

    [Python, Ruby] Needs random test cases

  • donaldsebleung Avatar

    [JS] Needs random test cases

  • ptyshevs Avatar

    This comment has been hidden.

  • wshen324 Avatar

    in test case backWardsPrime2, 70207 is not a prime?

  • Schmidtbit Avatar

    This comment has been hidden.

  • fuzzball Avatar
    //Swift
    func backwardsPrime(_ start: Int, _ stop: Int) -> [Int] {
      return [13, 17, 31, 37, 71, 73, 79, 97]
    }
    

    This code failed the first sample test. why?

  • Tadar2001 Avatar

    This comment has been hidden.

  • KLVK Avatar

    In this kata ("Backwards Read Primes") I have received different results:

    1. start=7000, end=7100 your result="7027, 7043, 7057"; my result="7027, 7043, 7057" (the same);
    2. start=70000, end=70245 your result="70001, 70009, 70061, 70079, 70121, 70141, 70163, 70241"; my result="70001, 70009, 70061, 70079, 70121, 70141, 70163, 70207, 70241" (diff. 70207);
    3. start=70485, end=70600 your result="70489, 70529, 70573, 70589"; my result=""70489, 70507, 70529, 70573, 70589"" (diff. 70507);
    4. start=60000, end=70000 your result=""; my result="" (the same); Why I have different results in test #2 and #3 ? May be you have some error in test or in task?

    I am using C language, but I think it is not important.

  • wilko98 Avatar

    This comment has been hidden.

  • nomadfarmer Avatar

    I'm not quite sure how to to report this, but this kata is basically the same as https://www.codewars.com/kata/emirps

  • mentalplex Avatar

    R translation has no sample test cases (just the dummy "example" that prepopulates the field when you start a translation).

  • nitish1986 Avatar

    This comment has been hidden.

  • omargr90 Avatar

    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?

  • mikemiksch Avatar

    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?

  • skout90 Avatar

    This comment has been hidden.

  • looongcatz Avatar

    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?

  • Ajko Avatar

    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

  • biillts Avatar

    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.

  • gmaljongm Avatar

    Say no to IntStream

  • mihirp93 Avatar

    [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

  • obitech Avatar

    Hey guys, I'm passing the test but I'm always getting this:

    Test Results:
    backwardsPrime
    ShouldPassAllTheTestsProvided
    ✔ Test Passed
    ✘ Test Crashed
    Exit code: 0
    Signal code: 6
    STDERR:
    *** Error in `/home/codewarrior/solution': free(): invalid size: 0x00007ffcf2a501a0 ***
    

    I'm using C

  • saadixl Avatar

    I am getting this: Expected: [9923, 9931, 9941, 9967], instead got: [9923, 9931, 9941, 9967]

    What's wrong here? (Using JS)

  • marudine Avatar

    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.

  • KSTNR Avatar

    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)

  • user8992180 Avatar

    Thank you very much. I am blind.

  • user8992180 Avatar

    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.

  • menaduke Avatar

    This comment has been hidden.

  • llxxee Avatar

    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

  • lilsnyderio Avatar

    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

  • Sokafootball Avatar

    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.

  • Larzan Avatar

    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'

  • nlile Avatar

    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!

  • ignovak Avatar

    This comment has been hidden.

  • Jotha Avatar

    What's about 727. This is a prime and a backwards a prime, too! In C# test it's not included in solution outputs.

  • ibcoleman Avatar

    This comment has been hidden.

  • dheerajjoshim Avatar

    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?

  • Askovacic Avatar

    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?

  • kentMol Avatar

    using c#. it's solved but when i submitted it. => ahh... Process was terminated. It took longer than 6000ms to complete.

  • D7689 Avatar

    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.

  • user8923521 Avatar

    Favorite kata so far. Not a fan of the interface presented by the backwardsPrime method (string?!), but the puzzle was cool nonetheless.

  • GaurangTandon Avatar

    Please include in the description that start and end are both inclusive. I just published a JS translation. Accept it if you like please!

  • bkaes Avatar

    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.

  • bkaes Avatar

    The Haskell tests aren't really idiomatic hspec tests: describe "..." should use the function's name, and it "..." should use something like "should <do something>", e.g.

    describe "backwardsPrime" $ do
      it "should work for some examples" $ do
        ...
        ...
      it "should only return numbers in the range" $ do
        ...
        ...
      it "should only return prime numbers" $ do
        ...
        ...
    

    Why? Because it will lead to the following output:

    backwardsPrime
      should work for some examples
      should only return numbers in the range
      should only return prime numbers
    

    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:

    import Text.Printf (printf)
    
    testBackwardsPrime :: Integer -> Integer -> [Integer] -> Expectation
    testBackwardsPrime f l r = 
      it (printf "should return the correct primes between %i and %i" f l) $
        backwardsPrime f l `shouldBe` r
        
    main = hspec $ do
      describe "backwardsPrime" $ do
        testBackwardsPrime  7000 7100 [7027,7043,7057]
        testBackwardsPrime 70000 70245 [70001,70009,70061,70079,70121,70141,70163,70241]
    

    This will lead to the following output:

    backwardsPrime
      should return the correct primes between 7000 and 7100
        TEST PASSED
      should return the correct primes between 70000 and 70245
        TEST FAILED, expected...
    

    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.

  • adam-tokarski Avatar

    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?

  • ChristianECooper Avatar

    This comment has been hidden.

  • Osterhasy Avatar

    This comment has been hidden.

  • jolaf Avatar

    Type in the kata description, egal instead of equal.

  • jolaf Avatar

    There's a typo in Python starting solution, nd instead of end.