Skip to content

Commit

Permalink
add 2023 day 6
Browse files Browse the repository at this point in the history
  • Loading branch information
NimVek committed Dec 6, 2023
1 parent 8e44f02 commit bbe5490
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions y2023/d06/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__year__ = 2023
__day__ = 6
__title__ = "Wait For It"
2 changes: 2 additions & 0 deletions y2023/d06/cases/example.288.71503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200
50 changes: 50 additions & 0 deletions y2023/d06/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import math

from pydantic.dataclasses import dataclass

from aoc.lib.solution import SolutionBase

import logging


__all__ = ["Solution"]
__log__ = logging.getLogger(__name__)


@dataclass
class Data:
time: tuple[int, ...]
distance: tuple[int, ...]


class Solution(SolutionBase):
@staticmethod
def prepare(data):
return Data(
time=tuple(map(int, data[0][5:].split())),
distance=tuple(map(int, data[1][9:].split())),
)

@staticmethod
def ways(time, distance):
sqrt = math.sqrt(time**2 - 4 * distance)
return math.ceil(0.5 * (time + sqrt)) - math.floor(0.5 * (time - sqrt)) - 1

@staticmethod
def part_01(data):
return math.prod(
Solution.ways(time, distance)
for time, distance in zip(data.time, data.distance)
)

@staticmethod
def part_02(data):
time = int("".join(map(str, data.time)))
distance = int("".join(map(str, data.distance)))
return Solution.ways(time, distance)


if __name__ == "__main__":
import aoc.lib.main

aoc.lib.main.main(Solution)

0 comments on commit bbe5490

Please sign in to comment.