diff --git a/2023/d06/ex1/ex1.py b/2023/d06/ex1/ex1.py deleted file mode 100755 index 1cbd4b7..0000000 --- a/2023/d06/ex1/ex1.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import math -import sys - - -def solve(input: list[str]) -> int: - def parse_line(line: str) -> list[int]: - return [int(n) for n in line.split(":")[1].split()] - - def solve(time: int, distance: int) -> int: - # With n being the button-held-down time. - # We want to solve: (time - n) * n > distance - # So we want the number of intergers in ]n_1, n_2[, n_1 and n_2 roots of the quadratic - # a = -1, b = time, c = -distance - determinant = time**2 - 4 * distance - if determinant <= 0: - return 0 - max = time / 2 - delta = math.sqrt(determinant) / 2 - n_1 = max - delta - n_2 = max + delta - return math.ceil(n_2 - 1) - math.floor(n_1 + 1) + 1 - - times, distances = map(parse_line, input) - - return math.prod(solve(t, d) for t, d in zip(times, distances)) - - -def main() -> None: - input = sys.stdin.read().splitlines() - print(solve(input)) - - -if __name__ == "__main__": - main() diff --git a/2023/d06/ex1/input b/2023/d06/ex1/input deleted file mode 100644 index 078c0bb..0000000 --- a/2023/d06/ex1/input +++ /dev/null @@ -1,2 +0,0 @@ -Time: 56 71 79 99 -Distance: 334 1135 1350 2430 diff --git a/2023/d06/ex2/ex2.py b/2023/d06/ex2/ex2.py deleted file mode 100755 index fdc6ceb..0000000 --- a/2023/d06/ex2/ex2.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -import math -import sys - - -def solve(input: list[str]) -> int: - def parse_line(line: str) -> int: - return int("".join(line.split(":")[1].split())) - - def solve(time: int, distance: int) -> int: - # With n being the button-held-down time. - # We want to solve: (time - n) * n > distance - # So we want the number of intergers in ]n_1, n_2[, n_1 and n_2 roots of the quadratic - # a = -1, b = time, c = -distance - determinant = time**2 - 4 * distance - if determinant <= 0: - return 0 - max = time / 2 - delta = math.sqrt(determinant) / 2 - n_1 = max - delta - n_2 = max + delta - return math.ceil(n_2 - 1) - math.floor(n_1 + 1) + 1 - - time, distance = map(parse_line, input) - - return solve(time, distance) - - -def main() -> None: - input = sys.stdin.read().splitlines() - print(solve(input)) - - -if __name__ == "__main__": - main() diff --git a/2023/d06/ex2/input b/2023/d06/ex2/input deleted file mode 100644 index 078c0bb..0000000 --- a/2023/d06/ex2/input +++ /dev/null @@ -1,2 +0,0 @@ -Time: 56 71 79 99 -Distance: 334 1135 1350 2430