Created
June 19, 2019 03:33
-
-
Save Shaddyjr/8e9937d41d4f0b58ccfaa63ab9810efd 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
| # All credit to the following users on Code Wars: | |
| # aenik97, CSNqwer, kickh, joei26, suhlob | |
| opposite = {'NORTH': 'SOUTH', 'EAST': 'WEST', 'SOUTH': 'NORTH', 'WEST': 'EAST'} | |
| def dirReduc(plan): | |
| new_plan = [] | |
| for d in plan: | |
| if new_plan and new_plan[-1] == opposite[d]: | |
| new_plan.pop() | |
| else: | |
| new_plan.append(d) | |
| return new_plan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment