Algorithm/codewars

Take a Ten Minute Walk 답안

Bonita SY 2021. 4. 1. 20:15
728x90
반응형

문제)

www.codewars.com/kata/54da539698b8a2ad76000228/train/python

 

Codewars: Achieve mastery through challenge

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com

 

내가 푼 답)

def is_valid_walk(walk):
    if (len(walk) != 10):
        return False
    
    ns = [1 for w in walk if w == 'n']
    ss = [1 for w in walk if w == 's']
    es = [1 for w in walk if w == 'e']
    ws = [1 for w in walk if w == 'w']
    
    if (ns == ss) and (es == ws):
        return True
    else:
        return False

성능 면에서는 루프를 4개나 도니까 별로일 것 같음

 

테스트 결과)

 

마음에 드는 다른 사람 소스)

ㄷㄷ count가 있었구나

728x90
반응형

'Algorithm > codewars' 카테고리의 다른 글

Human readable duration format 답안  (0) 2021.04.01
IQ Test 답안  (0) 2021.04.01
Credit Card Mask 답안  (0) 2021.04.01
Format a string of names like 'Bart, Lisa & Maggie'. 답안  (0) 2021.04.01
Catching Car Mileage Numbers 답안  (0) 2021.04.01