64 lines
1.4 KiB
Python
64 lines
1.4 KiB
Python
#!/bin/python3
|
|
import sys,time,re,os,copy
|
|
from pprint import pprint
|
|
sys.path.insert(0, '../../')
|
|
from fred import *
|
|
|
|
start_time = time.time()
|
|
|
|
if sys.argv[1] == 'test':
|
|
input_f = 'test'
|
|
elif sys.argv[1] == 'input':
|
|
input_f = 'input'
|
|
elif sys.argv[1]:
|
|
input_f = sys.argv[1]
|
|
else:
|
|
print('No argv provided')
|
|
exit()
|
|
|
|
|
|
def file2graph(f):
|
|
graph = {}
|
|
for line in open(f):
|
|
l = line.split(':')
|
|
key = l[0].strip()
|
|
nodes = l[1].rstrip().split()
|
|
graph[key] = nodes
|
|
return graph
|
|
|
|
#########################################
|
|
# #
|
|
# Part 1 #
|
|
# #
|
|
#########################################
|
|
|
|
def part1():
|
|
graph = file2graph(input_f)
|
|
result = dfs_all_paths(graph,'you', 'out',[])
|
|
|
|
return len(result)
|
|
|
|
start_time = time.time()
|
|
p1 = part1()
|
|
print('Part 1:',p1, '\t\t', round((time.time() - start_time)*1000), 'ms')
|
|
|
|
#########################################
|
|
# #
|
|
# Part 2 #
|
|
# #
|
|
#########################################
|
|
|
|
def part2():
|
|
if sys.argv[1] == 'test':
|
|
graph = file2graph('test2')
|
|
else:
|
|
graph = file2graph('input')
|
|
|
|
score = 0
|
|
|
|
return score
|
|
|
|
start_time = time.time()
|
|
p2 = part2()
|
|
print('Part 2:',p2, '', round((time.time() - start_time)*1000), 'ms')
|