Created
June 19, 2019 03:04
-
-
Save Shaddyjr/0d896fb66548dc76da4832659a5d1d0c to your computer and use it in GitHub Desktop.
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 dirReduc(arr): | |
directions = { | |
"NORTH" : "SOUTH" , | |
"SOUTH" : "NORTH" , | |
"WEST" : "EAST" , | |
"EAST" : "WEST" | |
} | |
output = [] | |
i = 0 | |
while(i < len(arr)-1): | |
move = arr[i] | |
next_move = arr[i+1] | |
if (next_move == directions[move]): | |
i += 2 | |
else: | |
output.append(move) | |
i+=1 | |
return output | |
# testing - should return ["WEST"] | |
dirReduc(["NORTH", "SOUTH", "SOUTH", "EAST", "WEST", "NORTH", "WEST"]) | |
# Doh! ['SOUTH', 'NORTH'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment