Ad
  • Custom User Avatar

    Approved

  • Custom User Avatar

    Done! Thank you!

    Now it looks way more neat, I like it this way as well :)

    (And sorry I took a little too long to reply, coulnd't access codewars at all yesterday...)

  • Custom User Avatar

    Good :)

    Just one detail: with 1000 random tests, it's very heavy and actually not useful to print an It for each random test. I think it's better to make just one Describe("Tests", func() block and include all the random tests in a It("Random tests", func() { block inside it. This will display only one message: Test passed if all the tests passed, otherwise one custom message for the first failed test; also, it avoids to run all the tests for nothing if one test is failing. That's most katas do and it has my preference.

  • Custom User Avatar

    Fixed it! (I guess so...) Is it ok now?

  • Custom User Avatar

    The generalization does affect the definition. Generalizing from the whole numbers to the integers (includes negative numbers) makes it natural to generalize the definition of primes. It's strange to do so since generalizing to complex numbers is more useful.

    I read the description again. It leaves no ambuiguity, so the fault is on me. I just saw negative numbers and primes and assumed we would use a definition generelized to integers. I should have been more diligent before making an issue. My only excuse is that there are others.

  • Custom User Avatar

    Ok. Answer to this thread when you are done, I should receive a notification.

    If you want to see an example, you can have a look at this translation: https://www.codewars.com/kumite/62dc286ded71437251c8693f?sel=62dc286ded71437251c8693f

    It is an easy one, if you haven't solved it already, solve it and you will be able to see the translation.

  • Custom User Avatar

    Wikipedia's article first sentence is "A prime number (or a prime) is a natural number...". This excludes de facto negative integers. In the paragraph you mention: " The integers are a ring, and the prime numbers in the integers have been generalized to rings in two different ways,.." This is a generalization of prime numbers, and doesn't affect the definition of what is a prime number. Moreover, if anyone would have a doubt, the description clearly explains what must be considered a prime number in this kata. Removing the kata for this would just be ridiculous.

  • Custom User Avatar

    Thank you for the feedback! That's my first translation and I don't know a lot of nuances, so I genuinely appreciate your help :) I'll fix the translation as soon as possible.

  • Custom User Avatar

    You should add assertion messages to the test to give the input in case of failed test.

    The easiest way to do it is to create a function and call it to perform all the tests (fixed and random). Something like this:

    func doTest(int n, bool expected) {
      Expect(IsPrime(n)).To(Equal(expected), "With n = %d", n)
    }
    

    And then replace all the tests with

      doTest(n, expected)
    
  • Custom User Avatar

    You must keep some consistency with other languages. In most of them, the number of tests is high, and the values tested are much greater. Naive O(N) solutions must not pass. I suggest to increase the number of tests to 1000, and the maximum value to 2147483647 (max int32), that's what is done in C++ for example.

  • Custom User Avatar
  • Custom User Avatar

    Oh! Sorry, I didn't know my comment was visible since it was under a solution. Thank you!

  • Default User Avatar

    Please don't post spoilers without using Spoiler flag, as your comments are visible to everyone on front page - even those who haven't solved the kata; knowing the name of "the correct" algorithm or data structure to use is basically 80% of the way towards a solution in many cases.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution