advent-of-code/2017-python/solutions/day_01.py

26 lines
644 B
Python
Raw Normal View History

2021-11-01 16:40:46 +01:00
from solutions import BaseSolution
class Solution(BaseSolution):
2025-05-06 20:14:58 +02:00
input_file = "01.txt"
2021-11-01 16:40:46 +01:00
def __str__(self):
2025-05-06 20:14:58 +02:00
return "Day 1: Inverse Captcha"
2021-11-01 16:40:46 +01:00
def solve(self, puzzle_input, distance=1):
pi_length = len(puzzle_input)
2025-05-06 20:14:58 +02:00
return sum(
int(puzzle_input[pos])
for pos in range(pi_length)
if puzzle_input[pos] == puzzle_input[(pos + distance) % pi_length]
)
2021-11-01 16:40:46 +01:00
def solve_again(self, puzzle_input):
distance = len(puzzle_input) // 2
return self.solve(puzzle_input, distance)
2025-05-06 20:14:58 +02:00
if __name__ == "__main__":
2021-11-01 16:40:46 +01:00
solution = Solution()
solution.show_results()