From 4dec21f362c03136e9811a4f4c162fcd8c50544e Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 2 Dec 2021 17:39:03 +0100 Subject: Added day 10 --- day2/__init__.py | 63 -------------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 day2/__init__.py (limited to 'day2/__init__.py') diff --git a/day2/__init__.py b/day2/__init__.py deleted file mode 100644 index 1d65d13..0000000 --- a/day2/__init__.py +++ /dev/null @@ -1,63 +0,0 @@ -import re -from dataclasses import dataclass -from typing import Generator - -from aoc import BaseAssignment - - -matcher = re.compile( - pattern=r'(?P\d+)-(?P\d+) (?P\w): (?P\w+)' -) - - -@dataclass -class Item: - min: int - max: int - letter: str - password: str - - -class Assignment(BaseAssignment): - def parse_item(self, item: str) -> Item: - match = matcher.match(item).groupdict() - return Item( - min=int(match['min']), - max=int(match['max']), - letter=match['letter'], - password=match['password'], - ) - - def valid_password(self, item: Item) -> bool: - raise NotImplementedError('Implement Valid Password') - - def run(self, input: Generator): - valid_passwords = 0 - - for i in input: - if self.valid_password(i): - valid_passwords += 1 - - return valid_passwords - - -class AssignmentOne(Assignment): - def valid_password(self, item: Item) -> bool: - return item.min <= item.password.count(item.letter) <= item.max - - -class AssignmentTwo(Assignment): - def valid_password(self, item: Item) -> bool: - return ( - ( - item.password[item.min - 1] == item.letter - and - item.password[item.max - 1] != item.letter - ) - or - ( - item.password[item.min - 1] != item.letter - and - item.password[item.max - 1] == item.letter - ) - ) -- cgit v1.2.3