4 kyu

Permutational Primes

278 of 502raulbc777
Description
Loading description...
Algorithms
Sorting
Permutations
Mathematics
Memoization
Data Structures
  • Please sign in or sign up to leave a comment.
  • LilithDragoness Avatar

    The Ruby test suite includes three additional tests that are not present in the other language versions:

    dotest(2000, 1, [64, 13, 1979])
    dotest(2000, 2, [14, 113, 1789])
    dotest(2000, 3, [7, 149, 1193])
    

    However, these tests are incorrect. For instance, 1979 has four prime permutations: [1997, 7919, 9719, 9791].

  • tobeannouncd Avatar
  • MarkShcerbakov Avatar

    Very good Kata! Thanks to author!!!

  • ahmet_popaj Avatar

    Great kata of the series to practice with, quite challenging indeed.

  • maxspiri Avatar

    cool kata!

  • benjaminzwhite Avatar

    Nice kata Raul as always!

    Just a small suggestion - to illustrate the part about all the permutations of each prime needing to be less or equal than n_max not just the "initial" prime:

    Currently all examples in description involve n_max = 1000 , therefore all the 1/2/3 digit numbers obtained by permutation will always be < 4 digits < 1000, so the above requirement is not illustrated in such cases.

    If you gave a single prime example with, e.g., n_max = 6000 you could illustrate the expected behaviour - something like:

    "For n_max = 6000, k_perms = 3 the prime p = 2851 is not a valid candidate because although it is itself <= 6000, and does have k = 3 other permutations that are prime: 5281, 5821, 8521, not all of these 3 permutations are <= 6000."

  • guuzaa Avatar

    The prime below 1000 with three prime permutations should include 136.

    136 => 163, 613, 631
    

    Do I say it right? I'm so confused.

  • Szymon83 Avatar

    If the permutation of a number is above the n_max, we don't count it, right?

  • sid114 Avatar

    also the kata that got me to 10k honor ;)

  • sid114 Avatar
  • depial Avatar
  • Sherbet2411 Avatar

    This comment has been hidden.

  • dfhwze Avatar
  • akar-0 Avatar
  • akar-0 Avatar
  • akar-0 Avatar
  • Rcinos Avatar

    Ruby 3.0 should be enabled

  • FArekkusu Avatar

    the number of prime permutations (k_perms) that the primes should generate below n_max

    The limit is actually inclusive, and there should be fixed tests to explicitly verify the correct behavior, e.g. permutational_primes(17209, 4) == [50, 1013, 13597].

  • StijnJvT Avatar

    The kata asks to return the number of, smallest, and largest (permutational) prime. As written, I would give different answers to the ones desired.

    To illustrate the issue, consider the example n = 1000, k = 3:

    149 ==> 419 ==> 491 ==> 941 179 ==> 197 ==> 719 ==> 971 379 ==> 397 ==> 739 ==> 937

    for which we are asked to find [3, 149, 379]. However, looking at the above 12 prime numbers that are all below 1000, clearly 971 is the largest, and without further specification, I would say the answer is [3, 149, 971], not [3,149,379].

    One way to "fix this up" is to say that given a set of primes related by digit permutation, in this kata "the" permutational prime is considered to be the smallest prime in this set. I do not think this is great terminology however, as all primes in a set of permutations are "permutational". In my opinion it would be better to either rewrite the tests to reflect the answer to the question as currently stated (though slightly easier to answer in my current approach at least), or to just specify that we want to find the smallest and biggest of the smallest prime in each set of primes related by permutations.

  • cliffstamp Avatar

    This still links to the original Kata which looks to be unpublished? Which I didn't even notice and solved it anyway and only discovered that when I noticed I could not submit it.

  • vladplazmius Avatar

    This comment has been hidden.

  • Firefly2002 Avatar

    Ruby translation submitted, seems to be working.

  • KenKamau Avatar

    I'm probably misunderstanding the question here, but can someone explain this?

    In the test for find_prime_kPerm(2000,1), I get [45, 13, 1999] should equal [64, 13, 1979]. The Kata expects the max prime to be 1979. But as far as I can tell, 1979 has 4 prime permutations as follows: 1979 -> 9791, 7919, 1997, 9719. Therefore, I cannot understand how the the Kata expects the max prime to be 1979 in this case.

  • Voile Avatar

    There are no mentions how 0s and duplicates are handled.

    The kata only accept a permutational prime if it has the same amount of digits as the number you're considering. There are ambiguities to this, e.g 107 only counts as having 1 permutation (701) while 17 and 71 are not considering to be related.

    (Then of course, you have numbers like 5881.)

  • Voile Avatar

    You should encapsulate your global variables inside a closure so it doesn't clash with user global variables (especially since you're using a function named primes which is highly likely to cause a collision).

  • Blind4Basics Avatar

    This comment has been hidden.