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

26 lines
699 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 = "04.txt"
2021-11-01 16:40:46 +01:00
def __str__(self):
2025-05-06 20:14:58 +02:00
return "Day 4: High-Entropy Passphrases"
2021-11-01 16:40:46 +01:00
def validate(self, passphrase, extended=False):
words = passphrase.split()
if extended:
2025-05-06 20:14:58 +02:00
words = ["".join(sorted(w)) for w in words]
2021-11-01 16:40:46 +01:00
return sorted(list(set(words))) == sorted(words)
def solve(self, puzzle_input):
return sum(self.validate(p) for p in puzzle_input.splitlines())
def solve_again(self, puzzle_input):
return sum(self.validate(p, True) for p in puzzle_input.splitlines())
2025-05-06 20:14:58 +02:00
if __name__ == "__main__":
2021-11-01 16:40:46 +01:00
solution = Solution()
solution.show_results()