-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday01.py
More file actions
29 lines (20 loc) · 732 Bytes
/
day01.py
File metadata and controls
29 lines (20 loc) · 732 Bytes
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
from day import Day
class Captcha:
def __init__(self, sequence):
self.seq = sequence
self.offset_next = self.solve(1)
self.offset_halfway = self.solve(len(sequence) // 2)
def solve(self, offset):
result = 0
shifted_seq = self.seq[offset:] + self.seq[:offset]
for current_digit, next_digit in zip(self.seq, shifted_seq):
if current_digit == next_digit:
result += int(current_digit)
return result
class Day01(Day):
def __init__(self, sequence):
self.captcha = Captcha(sequence)
def solve_part_one(self):
return self.captcha.offset_next
def solve_part_two(self):
return self.captcha.offset_halfway