-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.py
More file actions
139 lines (96 loc) · 2.4 KB
/
template.py
File metadata and controls
139 lines (96 loc) · 2.4 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/env python3
import copy
import operator
import re
import sys
from collections import Counter, defaultdict, deque
from itertools import permutations, combinations, product
import itertools
import aocd
flatten = itertools.chain.from_iterable
is_sample = False
DAY = # TODO: change me
YEAR = 2020
DIRS = {
0: (1, 0),
1: (0, 1),
2: (-1, 0),
3: (0, -1),
}
DDIRS = {
0: (1, 0),
1: (1, 1),
2: (0, 1),
3: (-1, 1),
4: (-1, 0),
5: (-1, -1),
6: (0, -1),
7: (1, -1),
}
def vec_add(*args):
return tuple(map(sum, zip(*args)))
def vec_mul(vec, k):
return tuple(map(lambda x: x * k, vec))
def bfs(graph, start):
visited = set()
order = []
q = deque([start])
while q:
cur = q.popleft()
if cur in visited:
continue
visited.add(cur)
order.append(cur)
for nbr in graph[cur]:
q.append(nbr)
return order
##########################################################################
def main(A):
# Solve part 1
def part1():
pass
res = part1()
submit_1(res)
# Solve part 2
def part2():
pass
res = part2()
submit_2(res)
##########################################################################
def parse_token(x):
#x = int(x)
return x
def parse_line(line):
#line = line.split()
#line = re.findall(r'\d+', line)
#line = re.findall(r'[-+]?\d+', line)
#m = re.fullmatch(r"<(.*), (.*), (.*)>", line)
#line = [parse_token(x) for x in line]
# One token per line
#line = line[0]
return line
def parse_input(A):
A = A.strip()
A = A.splitlines()
A = [parse_line(line) for line in A]
# One line per input
#A = A[0]
return A
##########################################################################
def submit_1(res):
print('Part 1', res)
if not is_sample and not input("skip? "):
puzzle.answer_a = res
def submit_2(res):
print('Part 2', res)
if not is_sample and not input("skip? "):
puzzle.answer_b = res
##########################################################################
if __name__ == '__main__':
if len(sys.argv) >= 2 and sys.argv[1].startswith('s'):
A = open('sample.txt').read()
is_sample = True
else:
puzzle = aocd.models.Puzzle(day=DAY, year=YEAR)
A = puzzle.input_data
main(parse_input(A))