Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created June 19, 2019 03:04
Show Gist options
  • Save Shaddyjr/0d896fb66548dc76da4832659a5d1d0c to your computer and use it in GitHub Desktop.
Save Shaddyjr/0d896fb66548dc76da4832659a5d1d0c to your computer and use it in GitHub Desktop.
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