day04
This commit is contained in:
parent
1afe9641ba
commit
37aad25422
45
day04.py
Normal file
45
day04.py
Normal file
@ -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
|
||||||
1
inputs/input04
Normal file
1
inputs/input04
Normal file
@ -0,0 +1 @@
|
|||||||
|
245318-765747
|
||||||
Loading…
Reference in New Issue
Block a user