Ad
  • Custom User Avatar

    did you benchmark and compare this solution to yours?
    whats the result?

    my guess is you solution is even worse because of regular string reallocations in output += MORSE_CODE[item] and try/except is not free either

    double loop solution is simple and easy to understand - split words, split letters, convert, join letters to words, join words to sentence

    your solution:
    split by space and try to decode each "letter"
    if next "letter" is '' then it must be word separator - append space, and on next cycle too, and on next
    and wrap it in try/except because processing last letter will cause list index out of range. exception in morse[index + 1]

    flow control via exceptions is a big no-no

    and it took me almost 10 mins to comprehend your algorithm

  • Custom User Avatar

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

  • Custom User Avatar

    too much cleaning in string

  • Custom User Avatar

    UB stands for 'undefined behavior'

  • Custom User Avatar

    works with MRI atm
    but modifying array while iterating leads to UB

  • Custom User Avatar
    1. ["NORTH", "WEST", "SOUTH"] can be simplified to just ["WEST"] but its unclean from the description you cant do that, only immediate returns to the same point must be simplified (may be there is a wall to the west of starting point)

    2. ["NORTH", "WEST", "SOUTH", "EAST"] and other "cyclic" paths that returns you to the same point should not be simplified. (too hard for this kata level?)

    please update kata description to clarify these statements
    "So the task is to give to the man a simplified version of the plan." is too vague