4 kyu

Largest Numeric Palindrome

159 of 653qaiken
Description
Loading description...
Algorithms
Performance
  • Please sign in or sign up to leave a comment.
  • fragged_again Avatar

    There's nothing more humbling than finishing a performance kata and then seeing all the elegant solutions ;_;

  • ahmet_popaj Avatar

    Amazing and wonderful kata.

  • karno-bh Avatar

    This comment has been hidden.

  • oxdium Avatar

    This comment has been hidden.

  • oxdium Avatar

    As 937 * 113 = 105881 and the largest palindromic number that can be arranged from the digits of result is: 81518

    why answer not 105501?

  • benjaminzwhite Avatar

    This comment has been hidden.

  • zayniddindev Avatar

    I think there are errors in tests: Testing for 7, 23, 87, 32210 -> expected 5417145 to equal 8510158

  • MikeKhz Avatar

    Guys, we read carefully: a product of any number of arguments!

  • user9644768 Avatar

    Ruby 3.0 should be enabled.

  • RealKenshiro Avatar

    Very clever edge cases!

    Nice kata but the two different tasks are not really related...

  • PabloLec Avatar

    I keep timing out :(

    My script executes in 86ms on an online Python interpreter with this input (937,113,4782,1,456,0,24,7824,13,6985). Seems quite efficient to me.

    What kind of test is taking so long ? How can I find it ?

  • GolivetsAndreu Avatar

    Why for 3534 the largest palindrom is 353, but not 535? 535 bigger then 353.

  • anter69 Avatar

    As the ranking cannot be changed (4 kyu) I turned it into a performance kata. Ruby & python are done, but need some help with JS. @Voile?

    Also updated description to be more clear

  • mark555 Avatar

    Not sure this is an issue or I am just dumb. Can someone please verify output of following (random) input: [JavaScript] Input [82730, 3117, 3, 61] results in Expected: 310070013, instead got: 9513159 and I am not sure if this test result is correct.

    Many thanks

  • Diziet Avatar

    I think this question should have more aggressive constraints for performance.

  • hhummel Avatar

    Thanks for the kata! I used numpy to calculate the products, which introduced roundoff errors that were hard to spot. Numpy is expecting a large data set more than large individual numbers. I switched to an obvious homegrown, (and not very efficient), function for the products, which fixed it.

  • xxharry Avatar

    I get "414 should equal 868" for the test (numeric_palindrome(48,9,3,67),868). However when I run my code on my machine I get the right answer. I have created a list called palindrome which stores all the possible palindromes and my function returns max(palindrome) which is clearly 868. Any ideas welcome.

  • JinySong Avatar

    Is it me or is it a bug?

    [ 15, 125, 8 ] product = 15000 pairs = { '0': 1 } singles = ['0', '1', '5' ] highest single = 5 result = 050 = 5

    ✘ Expected: 8, instead got: 5

  • jdog Avatar

    If you're going to make a nonsense kata, at least make it only one nonsense task.

    This should be two kata.

    i) find all possible product combinations of arguments ii) find largest palindromic number from this jumble of digits

    Combining the two is just painful and stupid.

    --

  • alexandersmanning Avatar

    This comment has been hidden.

  • ptchiangchloe Avatar

    '1875 generates the largest palindrome number, namely 8?' Anyone can hep me understand that? Thanks!

  • YDrall Avatar

    Can someone please verify output of following inputs:[Python]

    1. Testing for [5, 38, 17, 95, 88671, 586, 73518, 517, 66]
      It should work for random tests too: 9765332209022335679L should equal 9865443007003445689L
    2. Testing for [19034, 6334, 195, 5156, 763, 8766, 147, 22, 30581, 74]
      It should work for random tests too: 977654433211040112334456779L should equal 99888766532000200023566788899L
      ... and for other random test cases with argument size >5

      for input 1:

      Output of my code: Pastebin

      As my code is generating all possible permutation but I don't think there is any permutation to generate this output (Correct me if I am wrong).
  • MarkFurniture Avatar

    This was by far my favourite kata so far.

    I thought I was so clever with my first attempt, using a simpler "traditional" approach but this kata forced me to think about the task in a completely different way to how I normally would approach it.

    Excellent work!

  • MFBrewster Avatar

    Two things: First, the test case [34735, 56] should resolve to 373, but instead expects 191.

    Secondly, all of the random tests give me this error. ReferenceError: res is not defined at sol_get_comb at sol at Object.Test.it at Object.Test.describe

    at [eval]:5:6
    

    The predefined tests all passed so I don't think it's a problem with my code. Help would be appreciated!

  • MFBrewster Avatar

    I like this kata, and I am 99% sure I have a solution, but one of the tests is buggy. I logged its inputs: 15, 125, 8. These numbers have a product of 15000, the largest palindrome from which is 5. The test says it's expecting 8, which I just don't think is right. All of my other tests pass. Please give me my magic internet points!

    Edit: I'm sorry, I didn't see that it should be looking for the largest palindrom from ANY AMOUNT of the arguments. My bad.

  • xvlc Avatar

    Add a test case for args (1, 96, 3612) which should result in 9 and NOT in 7 (as it is accepted now). This was already said by jolaf.

  • xvlc Avatar

    This comment has been hidden.

  • xvlc Avatar

    This comment has been hidden.

  • xvlc Avatar

    As the solutions http://www.codewars.com/kata/reviews/557226b6385f599aac0000e2/groups/57113fc6b25a464f3c000008 and http://www.codewars.com/kata/reviews/557226b6385f599aac0000e2/groups/570e4f46e5c9a0b18d001323 are very very slow for args with many 0 and 1 I suggest to add a time limit in the test. I.e. add a test case numeric_palindrome(0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,57,62,23)

    with a time limit.

  • xvlc Avatar

    This comment has been hidden.

  • jessehorne Avatar

    This comment has been hidden.

  • kirilloid Avatar

    This comment has been hidden.

  • killer_mike Avatar

    That was no doubt the hardest Kata I have completed so far. Excellent job. The randomized test cases certainly kept me on my toes!

  • GiacomoSorbi Avatar

    Kata approved :)

  • jolaf Avatar

    Cool kata!

    However, it seems to be a bug in random tests (in Python):

    Testing for [1, 96, 3612]
    It should work for random tests too: 9 should equal 7
    
    Testing for [34735, 56]
    It should work for random tests too: 373 should equal 191
    
    Testing for [121, 1, 711]
    It should work for random tests too: 171 should equal 8
    
    Testing for [9, 61867]
    It should work for random tests too: 686 should equal 585
  • GiacomoSorbi Avatar

    Great kata :)!

    Just translated it into both Ruby and Python with plenty of random tests and also some good edge case, if you want to approve it.

    I would like to add random tests to the JS version if it is ok with you.

  • surtich Avatar

    I think you should add some random tests.

  • surtich Avatar

    Your solution does not work with some numbers. For example:

    numericPalindrome(11,1)
    numericPalindrome(2211,1)