From 37aad254224e0974cd606500dd8c44b5be037fdb Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sat, 27 Nov 2021 06:00:13 +0100 Subject: [PATCH] day04 --- day04.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ inputs/input04 | 1 + 2 files changed, 46 insertions(+) create mode 100644 day04.py create mode 100644 inputs/input04 diff --git a/day04.py b/day04.py new file mode 100644 index 0000000..09b230e --- /dev/null +++ b/day04.py @@ -0,0 +1,45 @@ +from aoc import AOCDay +from typing import Any + + +class Day(AOCDay): + test_solutions_p1 = [] + test_solutions_p2 = [] + + def part1(self) -> Any: + low, hi = map(int, self.input[0].split("-")) + count = 0 + for x in range(low, hi + 1): + d0 = x // 100_000 + d1 = x % 100_000 // 10_000 + d2 = x % 10_000 // 1_000 + d3 = x % 1_000 // 100 + d4 = x % 100 // 10 + d5 = x % 10 + + if d0 <= d1 <= d2 <= d3 <= d4 <= d5: + if d0 == d1 or d1 == d2 or d2 == d3 or d3 == d4 or d4 == d5: + count += 1 + + return count + + def part2(self) -> Any: + low, hi = map(int, self.input[0].split("-")) + count = 0 + for x in range(low, hi + 1): + d0 = x // 100_000 + d1 = x % 100_000 // 10_000 + d2 = x % 10_000 // 1_000 + d3 = x % 1_000 // 100 + d4 = x % 100 // 10 + d5 = x % 10 + + if d0 <= d1 <= d2 <= d3 <= d4 <= d5: + if (d0 == d1 and d1 != d2) \ + or (d1 == d2 and d2 != d3 and d1 != d0) \ + or (d2 == d3 and d3 != d4 and d2 != d1) \ + or (d3 == d4 and d4 != d5 and d3 != d2) \ + or (d4 == d5 and d4 != d3): + count += 1 + + return count diff --git a/inputs/input04 b/inputs/input04 new file mode 100644 index 0000000..6190bcb --- /dev/null +++ b/inputs/input04 @@ -0,0 +1 @@ +245318-765747