-
Notifications
You must be signed in to change notification settings - Fork 0
/
day06.py
37 lines (21 loc) · 879 Bytes
/
day06.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
from aoc import *
def find(data, length):
return next(pos for pos in range(length, len(data))
if len(set(data[pos-length:pos])) == length)
def solve(file=6):
data = read_input_line(file)
return find(data, 4), find(data, 14)
print(solve())
def test():
test_strings = ("mjqjpqmgbljsphdztnvjfqwrcgsmlb",
"bvwbjplbgvbhsrlpgdmjqwftvncz",
"nppdvjthqldpwncqszvftbrmjlhg",
"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg",
"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw")
p1_solutions = (7, 5, 6, 10, 11)
p2_solutions = (19, 23, 23, 29, 26)
for test, solution in zip(test_strings, p1_solutions):
assert find(test, 4) == solution
for test, solution in zip(test_strings, p2_solutions):
assert find(test, 14) == solution
assert solve() == (1287, 3716)