5 kyu

Prime number decompositions

322 of 1,596user3482173
Description
Loading description...
Fundamentals
  • Please sign in or sign up to leave a comment.
  • Jam14man Avatar

    The behavior of the code in case of exceptions is completely not described. The task is a puzzle. And a waste of time.

  • saudiGuy Avatar

    python new test framework + random tests + snake_case (with backward compatibility) are required. updated in this fork

  • PyPro Avatar

    Just noticed a small typo that should be corrected, "exemple" should be example

  • ejini战神 Avatar

    Description should be language-agnostic

  • ivan.k Avatar

    There is a problem with tests for JS. I am getting the following warning:

    assertSimilar is deprecated, use assertDeepEquals

    Could please, someone fix this?

  • AfroYak Avatar

    If n=2, the function should respectively return [2], [[2],[1]], [2].

    Why would the list UniquePrimeFactorsWithCount include 1? Shouldnt the answer be: [2],[[2,1]],[2]

    e.g. Any prime number the answer should similarly be: [n_prime],[[1,n_prime]],[n,prime]

  • Mohrezakhorasany Avatar

    Fun kata, but description needs to be more clear! Thanks.

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • AvSBF Avatar

    literally had to use list of prime numbers up to 10000 idk how to do it in other ways

  • dihalt Avatar

    but where are the normal tests???

  • olimejj Avatar

    very fun but the description needs to be more clear about what to do with the errors. for example errors should return [] [[],[]] []

  • kipawaa Avatar

    Description contradicts itself, saying anything <= 0 should result in an error, and then proceeding to say [], [[], []], and [] should be returned for 0. EDIT: I realize now that the expected result for 0 is the expected result for all errors. This should be made more explicit, I'm not sure how I managed to solve without realizing this but it was not apparent to me upon reading the description.

  • jwhaley5 Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    Java: one function name is incorrect: getUniquePrimeFactorsWithProducts in the description becomes getPrimeFactorPotencies in the code. Either correct the java version or put a note in the description, in the related part.

  • newsh Avatar

    So frustrating. I'm doing Java.

    What is the expected return value for getPrimeFactorPotencies(long n) with n = 0?

    I'm returning new Long[]{} and test fails with null pointer exception.

  • Tuhaj Avatar

    there is a typo: exemple => example

  • anter69 Avatar

    Ruby, Pyhton:

    • no random tests
    • function names should use snake_case
  • Erynvorn Avatar

    Looks like more an exercize on handling errors and corner cases. Nothing to do with decomposition in prime numbers which is trivial. I got all errors in non math issues.

  • jakebowerbank Avatar

    The kata is on prime numbers yet asks to return 1 if n = 1.

    1 is not a prime number, and providing n = 1 should result in an error.

  • burnsy89 Avatar

    getUniquePrimeFactorsWithCount(n) - should this not keep the prime numbers in the same order, such that when n = 100, we get the result [[2, 2], [2, 5]]

  • Oogway Avatar

    I can't get it to work. First, I was using ArrayList in my solution, then test[2] failed with a java heap size message. Then I was using ordinary Arrays. Because one does not know in advance how big it had to be, I was using a logarithmic estimate on the size and afterwards copied it in an array of correct length. Then I got an "unknown test error" or something on test[2], while the other tests were passing. Ok, so I made an extra loop in advance to get the size of the Array before creating it. But then it takes too long on test[2] and the process terminates. I'm out of ideas.

  • le0 Avatar

    This comment has been hidden.

  • saraogurmeet Avatar

    i am submitting the code for java. The third kata test case is throwing this :::: getUniquePrimeFactorsWithCount: Expected 2-dimensional array with size 2 in first dimension expected:<2> but was:<0>

    when i printed the n, the value was 0. so the answer as the author has mentioned should be Long[][] {} . is there something wrong with the test case.

    if anyone could help please it would be very much appreciated.

  • chris2k59 Avatar

    This comment has been hidden.

  • hilary Avatar

    An interesting kata which has us working with the prime gem rather than asking us to pretend it doesn't exist. Thanks!

  • georgenwpu Avatar

    This comment has been hidden.

  • jingzhi22 Avatar

    This comment has been hidden.

  • aggronacho Avatar

    When I submit the code, it test the number 10 and the prime factors for 10 are: 2 and 5 but it throw this error

    [[1, 5], [1, 2]] should equal [[2, 5], [1, 1]]

    I don't understand why

    EDIT: sorry, now I understand why

  • GiacomoSorbi Avatar

    And now it has been translated into both Ruby and Python.

    I would still add some edge case with larger number and some random test to raise up difficulty a bit, but I hope that now with 3 option this kata will pass to the approved status soon enough :)

  • GiacomoSorbi Avatar

    Nice variation on the primes theme and quite challenging with all the edge cases, but never frustrating; thanks were_cat!

    Gladly marked as ready, just let me know if you could enjoy some Ruby and/or Python translations :)

  • kgashok Avatar

    This comment has been hidden.

  • OverZealous Avatar

    Just to reiterate what abekim said, you should take some time and clean up the descriptions for the other functions. It's not clear at all what those cases are asking for.

    Some other notes:

    • You should probably think about giving these functions more informative names. I'm not sure the best names, but even verbose names like this would work:

      • getAllPrimeFactors(n)
      • getUniquePrimeFactorsWithCounts(n)
      • getUniquePrimeFactorProducts(n)
    • You should think about having the invalid case for factorise2 be [[],[]]. This follows the law of least suprise: the result is in the same format if it's correct or incorrect.

    • Even better, have the failed case in all three examples throw an error. I'd even go so far as to having the case for 1 throw an error. In the real world, this puts the onus on the developer to determine how they want to handle edge cases, rather than returning an empty set.

    • There's no reason to convert the test values to strings, this just obfuscates the results. Rather, use Test.assertSimilar(). This renders the values better when they fail (such as [[2,5],[3,3]]), which is a lot easier to read than the flattened array (2,5,3,3).

    • You need to add descriptions to your tests. In fact, I recommend reading up on the describe() and it() methods to help you organize your tests. Something like this:

      describe('Simple tests', function() {
        it('should handle basic values', function() {
          Test.assertSimilar(factorise1(10), [2,5], 'Input of 10');
          //...
        });
        // Add more simple tests here
      });
      
      // Add more descibe blocks, such as one for "Error handling"
      

      Cleaning everything up in this sort of manner will significantly help the solver without them resorting to peppering their code with console.log() values. This is what having a good test suite is all about, anyway.

    The biggest benefit of writing good, well-organized tests here on CodeWars is it will (hopefully) make you a better developer in the real world. :-)

  • abekim Avatar

    This comment has been hidden.