-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hakan
authored and
Hakan
committed
Jul 16, 2020
1 parent
43953c2
commit 4e13c73
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# def dirReduc(arr): | ||
# for x in range(3): | ||
# i = 0 | ||
# while i < len(arr)-1: | ||
# if arr[i]=="NORTH" and arr[i+1]=="SOUTH": | ||
# arr.pop(i) | ||
# arr.pop(i) | ||
# elif arr[i]=="SOUTH" and arr[i+1]=="NORTH": | ||
# arr.pop(i) | ||
# arr.pop(i) | ||
# elif arr[i]=="EAST" and arr[i+1]=="WEST": | ||
# arr.pop(i) | ||
# arr.pop(i) | ||
# elif arr[i]=="WEST" and arr[i+1]=="EAST": | ||
# arr.pop(i) | ||
# arr.pop(i) | ||
# else: | ||
# i +=1 | ||
# return arr | ||
|
||
# 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 | ||
|
||
def dirReduc(arr): | ||
dir = " ".join(arr) | ||
dir2 = dir.replace("NORTH SOUTH",'').replace("SOUTH NORTH",'').replace("EAST WEST",'').replace("WEST EAST",'') | ||
dir3 = dir2.split() | ||
return dirReduc(dir3) if len(dir3) < len(arr) else dir3 | ||
plan = ["NORTH","EAST","WEST","SOUTH","WEST","WEST","NORTH"] | ||
print(dirReduc(plan)) |