-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserPipes_2023.py
52 lines (32 loc) · 1.08 KB
/
browserPipes_2023.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
#BOWSER PIPE
nPipes = int(input())
pipes = map(lambda x: int(x), input())
nPipesToEnter = int(input())
pipesToEnter = map(lambda x: int(x), input())
pipeToDestination = dict()
destinationToPipes = dict()
for i in range(len(nPipes)):
pipe = pipes[i]
coinRoomId = 0
if pipe == -1:
pipeToDestination[i] = (pipe, coinRoomId)
if destinationToPipes[(pipe, coinRoomId)] is None:
destinationToPipes[(pipe, coinRoomId)] = []
destinationToPipes[(pipe, coinRoomId)].append(i)
coinRoomId = coinRoomId+1
else:
if destinationToPipes[(pipe, i)] is None:
destinationToPipes[(pipe, i)] = []
pipeToDestination[(pipe, i)].append(i)
def traversePipe(start):
current = start
steps = 0
lastPipeEntered = start
while not current == -1:
destination, id = pipeToDestination[current]
current = destination
step = step + 1
lastPipeEntered = current
return (steps,lastPipeEntered)
for i in range(len(nPipesToEnter)):
pipeToEnter = pipesToEnter[i]