-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCC'02S3-Blindfold.py
81 lines (67 loc) · 2.08 KB
/
CCC'02S3-Blindfold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#CCC '02 S3 - Blindfold
#brute force, check every possibility for everything all for directions following instructions
num_rows = int(input())
num_cols = int(input())
backyard = []
for loops in range(num_rows):
line = input()
temp_line = list(line)
temp_line.insert(0,0)
temp_line.insert(len(temp_line),0)
backyard.append(temp_line)
backyard.insert(0,[0 for x in range(len(backyard[0]))])
backyard.insert(len(backyard),[0 for x in range(len(backyard[0]))])
#starting index i (1,1)
num_moves = int(input())
moves = []
for loops in range(num_moves):
temp_move = input()
moves.append(temp_move)
facing = ["N","E","S","W"]
def start(start_position, moves, direction):
'''
checks if a position is a possible starting position assuming the person starts of facing north
param: tuple (row,col), list , string
return boolean
'''
global backyard , facing
return_list = []
rotation = facing.index(direction)
row = start_position[0]
col = start_position[1]
for move in moves:
if move == "R":
rotation += 1
elif move == "L":
rotation -= 1
else:
if facing[rotation % 4] == "N":
row -=1
elif facing[rotation % 4] == "E":
col += 1
elif facing[rotation % 4] == "S":
row += 1
elif facing[rotation % 4] == "W":
col -= 1
if backyard[row][col] == 0 or backyard[row][col] == "X":
return_list.append(False)
return return_list
return_list.append(True)
return_list.append((row,col))
return return_list
possible_starts = set()
for row in range(len(backyard)):
for col in range(len(backyard[0])):
if backyard[row][col] == "." or backyard[row][col] == "*":
for direction in facing:
if start((row,col),moves,direction)[0]:
backyard[start((row,col),moves,direction)[1][0]][start((row,col),moves,direction)[1][1]] = "*"
#remove the zeros of top and bottom
backyard.pop(0)
backyard.pop(len(backyard)-1)
temp_str = ""
for row in range(len(backyard)):
for col in range(1,len(backyard[0])-1):
temp_str+= backyard[row][col]
print(temp_str)
temp_str = ""