-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp12a.py
53 lines (39 loc) · 880 Bytes
/
p12a.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
# https://adventofcode.com/2021/day/12 part 1
# Created by: Menaka S. 12 Dec 2021
import sys
lines = []
graph = set()
bigcaves = []
def isbigcave(word):
ucase = 1
for i in range(len(word)):
if word[i].upper() != word[i]:
ucase = 0
return ucase
def addnext(given,path):
for (st,ed) in graph:
if st == given:
if ed not in bigcaves and path.find(',' + ed) > 0:
continue
if ed == 'end':
paths.add(path + ',' + ed)
else:
addnext(ed,path + ',' + ed)
for line in sys.stdin:
line = line.strip()
(lhs,rhs) = line.split('-')
if rhs == 'start':
lhs, rhs = rhs, lhs
graph.add((lhs,rhs))
if lhs != 'start' and rhs != 'end':
graph.add((rhs,lhs))
if isbigcave(lhs):
bigcaves.append(lhs)
if isbigcave(rhs):
bigcaves.append(rhs)
#print(graph)
#print(bigcaves)
paths = set()
given = 'start'
addnext(given,'start')
print(len(paths))