Ad
  • Custom User Avatar

    same Problem :-()

  • Custom User Avatar

    I actually have no idea of what to do with random test cases. It seems there is many many many non-alpha character that should be delim, and I don't know what to do.

    Quite frustrating... Wish someone's help.

    My code is written in Haskell.

    Test Results:
    A9n
    abbreviate
    should a8e abbreviation
    should a8e internationalization
    should a8e Accessibility
    should a8e accessibility
    should a8e 'elephant-ride'
    should work for the example words
    randomized tests
    should return the same as the solution
    Falsifiable (after 19 tests and 6 shrinks): 
    expected: "a2a"
     but got: "aa\50892a"
    "aa\50892a"
    
  • Custom User Avatar

    One should implement its own argmax.

    Edited: Oh! One could do reverse before words.

  • Custom User Avatar

    This code is in fact not correct, because maximumBy will not return the first element with highest score but the final one.

    For example, if we use the test "ab ba" (which should return "ab"), the code cannot pass.

  • Custom User Avatar
  • Custom User Avatar

    It seems to me that codewars does not give a strong suggestion for users to write efficient code

    This is a 6kyu kata, which is on the easier end. For harder kata, it's common to not let inefficient code pass (because there's a limited time in which all tests must finish, which is 12s for most languages). You can check the tags: Where efficient code is requested, the tags will often include 'performance'.

  • Custom User Avatar

    Thanks for your quick reply! Maybe I should take some time to get more familiar with codewars community. It seems to me that codewars does not give a strong suggestion for users to write efficient code, for I haven't seen statistics about time & memory usage (about others' code)... (Maybe I could upgrade to red).

    Back to this problem, I still think that algorithm design should stick to the problem itself. The impact caused by the input seems to be not so relevent to me though... (Although the private timer could not measure it as you have said :-))..

    And I really appreciate your idea that we could "streamize" the array to accelerate the code.

    Thanks again!

  • Custom User Avatar

    Why shouldn't we use binary search? I haven't seen a sample code with it.

    Because it isn't necessary? The thing is we are going to spend linear time generating the array anyway.

    Binary search is the most appealing if you have a static sorted (in some way) array, and you need to search in it multiple times. If you are just going to search through it one for one thing, to improve efficiency you should probably consider how you can make the array a stream or something to avoid storing large number of values, or maybe how you can eliminate the array altogether.

    The inefficiency you mentioned can be revealed if you directly measure the time took by the function... But apparently this was not done :) If you want to, when you get enough points, you can create your speed version of this kata. Make sure to do it well though, bad quality kata are not something really tolerated here.

  • Custom User Avatar
  • Custom User Avatar

    Why shouldn't we use binary search? I haven't seen a sample code with it.

    Accumulating or iterating all items does not seem to be efficent...