-
Notifications
You must be signed in to change notification settings - Fork 0
/
aoc_util.py
101 lines (64 loc) · 2.35 KB
/
aoc_util.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
def __read_and_strip(input_file):
with open(input_file, "r") as file:
lines = [ line.strip() for line in file ]
return lines
def borders_safe(position, width, height):
p_height, p_width = position
return 0 <= p_width < width and 0 <= p_height < height
def read_lists_01(input_file="data/24-aoc-01.in"):
left_list = []
right_list = []
with open(input_file, "r") as file:
for line in file:
values = line.split(' ')
left_list.append(int(values[0]))
right_list.append(int(values[-1]))
left_list.sort()
right_list.sort()
return left_list, right_list
def read_reports_03(input_file="data/24-aoc-03.in"):
reports = []
with open(input_file, "r") as file:
for line in file:
report = line.split(' ')
reports.append([int(level) for level in report])
return reports
def read_memory_muls(input_file="data/24-aoc-05.in"):
with open(input_file, "r") as file:
memory = "".join(file)
return memory
def read_wordsearch(input_file="data/24-aoc-07.in"):
return __read_and_strip(input_file)
def read_safety_manuals(input_file="data/24-aoc-09.in"):
ordering_rules = []
pages_to_produce = []
switched = False
with open(input_file, "r") as file:
for line in file:
if line.strip() == "":
switched = True
continue
if not switched:
ordering_rules.append(line)
else:
pages_to_produce.append(line)
return ordering_rules, pages_to_produce
def read_guard_path(input_file="data/24-aoc-11.in"):
return __read_and_strip(input_file)
def read_calibration_equations(input_file="data/24-aoc-13.in"):
with open(input_file, "r") as file:
equations = []
for line in file:
result, terms = line.strip().split(':')
terms = terms.strip().split(' ')
equations.append((int(result), [ int(term) for term in terms ]))
return equations
def read_antenna_map(input_file="data/24-aoc-15.in"):
return __read_and_strip(input_file)
def read_dense_disk_map(input_file="data/24-aoc-17.in"):
with open(input_file, "r") as file:
return ''.join(line.strip() for line in file)
if __name__ == "__main__":
import doctest
doctest.testmod()