Ad
  • Custom User Avatar

    Perfectly servicable and efficient. Wouldn't best practices encourage adding a return line? Obviously not necessary for such simple code.

  • Default User Avatar

    You can save one byte by using an operator different from the !=, but it's not well defined whether or not that's the desired behaviour, and I don't want to take any steps towards turning this into a solution remotely resembling lambda*_:532. If you make a fork that changes something other than that and improve the rules in a way that allows a shorter operator to be used, it might be a good thing to copmare against a hypothetical one byte shorter version of this that utilizes the < operator.

  • Custom User Avatar

    Yeah in JS yesterday it took me about an hour to get it working, but way too slow! Still haven't been able to improve it. May need to start over.

  • Custom User Avatar

    It took me about an hour to write it in Python mostly because I was having a difficult time returning the solution even as I was able to print it.
    What took me the longest time was to rewrite it in C++ as that is the language that I wanted to solve it.

  • Custom User Avatar

    Still there's the same problem with Python3, there's print() expression issue in test,
    as well as another one i get, if needed:
    Traceback (most recent call last):
    File "main.py", line 14, in
    testAndPrint(decodeMorse(decodeBits('1')), 'E')
    File "/home/codewarrior/solution.py", line 6, in decodeMorse
    return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
    File "/home/codewarrior/solution.py", line 6, in
    return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
    File "/home/codewarrior/solution.py", line 6, in
    return ' '.join(''.join(MORSE_CODE[letter] for letter in word.split(' ')) for word in morseCode.strip().split(' '))
    KeyError: '1'

  • Default User Avatar

    This is a tough one for me. I'm fairly new to coding. I know that I have to recursively call n-1, probably in a while loop. Just not what the base case is.
    I get way more values than I need in the result. Any tips or articles would be greatly appreciated. (I'm not from a math background but am tyring my best to grok this stuff).

  • Default User Avatar
  • Custom User Avatar

    no, sum just happens to accept a generator. That ord(c) for c in ... is a generator expression, and is not a list.

  • Custom User Avatar

    ord(c) for c in s.replace(' ', '')- I thought this semantic is for list comprehension, can i use it for every loop?

  • Custom User Avatar

    A generator expression gives the values (in this case the integers coming from ord(c)) one by one, instead of storing them in a list.

  • Custom User Avatar

    You're right, asymptotically it doesn't change anything.
    But a string takes much less space than a list of the same size so we're using at least two times less memory.

    But I'm nitpicking, honestly I just removed the brackets because it looks nicer that way.

  • Custom User Avatar

    str.replace has O(n) space complexity, so you're not really saving much.

  • Default User Avatar

    Can you please explain what is a generator expression?

  • Custom User Avatar

    Quite right. I never used this before but it works like a charm.

  • Custom User Avatar

    See the discussion down below with MastaB. Especially the last comment contains some hints.

  • Loading more items...