Last active
May 27, 2021 18:41
-
-
Save joan0fsnark/648553e0e01a44e47dc13abf277d9faa to your computer and use it in GitHub Desktop.
CodeWars: Take a Ten-Minute Walk (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_valid_walk(walk): | |
ns = 0 | |
ew = 0 | |
if len(walk) == 10: | |
for step in walk: | |
if step == 'n': | |
ns += 1 | |
if step == 's': | |
ns -= 1 | |
if step == 'w': | |
ew += 1 | |
if step == 'e': | |
ew -= 1 | |
else: | |
return False | |
return ns == 0 and ew == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment