Ad
  • Custom User Avatar

    At first I wanted to say it is best practice but it takes a lot to understand the tricks that make it work. It is extremelly clever though but I would not say this is easy to modify if the code has to evolve. The changing direction condition is particularly difficult to read and this is probably why you added the comments but it could be a lot clearer by splitting into multiple "elif" in my opinion.

    I really like the self.moving and it is clever the way you use it in areSomeGuysWaitingSameWay_AtThatFloor and areSomeGuysWaitingOtherWay_AtThatFloor.

  • Custom User Avatar

    The sample test for test "aa" and "bob" expect false when they are in fact plaindromes.

  • Custom User Avatar
  • Custom User Avatar
    # You can generalise the function to only have one handling number by slice of 3 digit and call it recursively (here is a qwick exemple) 
    convertionTable={0:'zero ',1:'one ',2:'two ',3:'three ',4:'four ',5:'five ',6:'six ',7:'seven ',8:'eight ',9:'nine ',
    10:'ten ',11:'eleven ',12:'twelve ',13:'thirteen ',14:'fourteen ',15:'fifteen ',16:'sixteen ',17:'seventeen ',18:'eighteen ',19:'nineteen ',
    20:'twenty ',30:'thirty ',40:'forty ',50:'fifty ',60:'sixty ',70:'seventy ',80:'eighty ',90:'ninety '}
    
    def convert(num, depth=0):
        string = ""
        rest = num
    
        if(num > 999):
            string += convert(int(num/1000), depth+1)
            rest = rest%1000
    
        cent = int(rest/100)
        if(cent != 0):
            string += convertionTable[cent]+"hundred "
            rest = num%100
    
        if(rest and string and not depth):
          string += "and "
    
        diz = int(rest/10)
        if(diz > 1):
            string += convertionTable[diz*10]
            rest = rest%10
        elif(diz):
            string += convertionTable[rest]
            rest = 0
    
        unit = rest
        if(not string):
            string += convertionTable[unit]
        elif(unit > 0):
            string += convertionTable[unit]
        rest = 0
    
        if(depth == 2):
            string += "million "
        elif(depth == 1):
            string += "thousand "
        else:
            string = string.strip()
    
        return string
    
    
    print(convert(175684354))
    print(convert(515096))
    print(convert(1015))
    print(convert(1000))  
    print(convert(999))
    print(convert(0))
    print(convert(9))
    print(convert(10))
    print(convert(11))
    print(convert(20))
    print(convert(21))
    print(convert(32))
    print(convert(43))
    print(convert(76))
    
  • Custom User Avatar

    Duration of execution is a criteria but this shouldn't be THE criteria to determine the best solution. The best solution should be a fine balance between complexity(related to execution time), readability and best practice.

  • Custom User Avatar

    I think that in your case the comments don't make the code easier to read and understand otherwise your solution is clean. Maybe just less efficient since you used a dict instead of a set.
    Also you did the same "mistake" i did, you can get rid of the else statment because you always want to add the checked value.

  • Custom User Avatar

    had two issue before completing the kata with exactly the same code:

    first attempt I got:
    Signal:
    Process exited prematurely with a SIGKILL signal.

    second one i got this:
    STDERR:
    Traceback:
    in
    File "./frameworks/python/cw-2.py", line 22, in assert_equals
    equals_msg = "{0} should equal {1}".format(repr(actual), repr(expected))
    MemoryError

    finally on the third attempt it passes