diff --git a/README.md b/README.md index 646b8743..93ebe1f2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | | ---| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | -| python3 | [✓](src/main/python/AoC2023_01.py) | [✓](src/main/python/AoC2023_02.py) | [✓](src/main/python/AoC2023_03.py) | [✓](src/main/python/AoC2023_04.py) | [✓](src/main/python/AoC2023_05.py) | [✓](src/main/python/AoC2023_06.py) | [✓](src/main/python/AoC2023_07.py) | [✓](src/main/python/AoC2023_08.py) | [✓](src/main/python/AoC2023_09.py) | [✓](src/main/python/AoC2023_10.py) | [✓](src/main/python/AoC2023_11.py) | [✓](src/main/python/AoC2023_12.py) | [✓](src/main/python/AoC2023_13.py) | [✓](src/main/python/AoC2023_14.py) | [✓](src/main/python/AoC2023_15.py) | [✓](src/main/python/AoC2023_16.py) | [✓](src/main/python/AoC2023_17.py) | [✓](src/main/python/AoC2023_18.py) | [✓](src/main/python/AoC2023_19.py) | [✓](src/main/python/AoC2023_20.py) | [✓](src/main/python/AoC2023_21.py) | | [✓](src/main/python/AoC2023_23.py) | | | +| python3 | [✓](src/main/python/AoC2023_01.py) | [✓](src/main/python/AoC2023_02.py) | [✓](src/main/python/AoC2023_03.py) | [✓](src/main/python/AoC2023_04.py) | [✓](src/main/python/AoC2023_05.py) | [✓](src/main/python/AoC2023_06.py) | [✓](src/main/python/AoC2023_07.py) | [✓](src/main/python/AoC2023_08.py) | [✓](src/main/python/AoC2023_09.py) | [✓](src/main/python/AoC2023_10.py) | [✓](src/main/python/AoC2023_11.py) | [✓](src/main/python/AoC2023_12.py) | [✓](src/main/python/AoC2023_13.py) | [✓](src/main/python/AoC2023_14.py) | [✓](src/main/python/AoC2023_15.py) | [✓](src/main/python/AoC2023_16.py) | [✓](src/main/python/AoC2023_17.py) | [✓](src/main/python/AoC2023_18.py) | [✓](src/main/python/AoC2023_19.py) | [✓](src/main/python/AoC2023_20.py) | [✓](src/main/python/AoC2023_21.py) | | [✓](src/main/python/AoC2023_23.py) | [✓](src/main/python/AoC2023_24.py) | | | java | [✓](src/main/java/AoC2023_01.java) | [✓](src/main/java/AoC2023_02.java) | [✓](src/main/java/AoC2023_03.java) | [✓](src/main/java/AoC2023_04.java) | [✓](src/main/java/AoC2023_05.java) | [✓](src/main/java/AoC2023_06.java) | [✓](src/main/java/AoC2023_07.java) | [✓](src/main/java/AoC2023_08.java) | [✓](src/main/java/AoC2023_09.java) | [✓](src/main/java/AoC2023_10.java) | [✓](src/main/java/AoC2023_11.java) | [✓](src/main/java/AoC2023_12.java) | [✓](src/main/java/AoC2023_13.java) | [✓](src/main/java/AoC2023_14.java) | [✓](src/main/java/AoC2023_15.java) | [✓](src/main/java/AoC2023_16.java) | [✓](src/main/java/AoC2023_17.java) | [✓](src/main/java/AoC2023_18.java) | | [✓](src/main/java/AoC2023_20.java) | | [✓](src/main/java/AoC2023_22.java) | [✓](src/main/java/AoC2023_23.java) | | | | rust | [✓](src/main/rust/AoC2023_01/src/main.rs) | [✓](src/main/rust/AoC2023_02/src/main.rs) | [✓](src/main/rust/AoC2023_03/src/main.rs) | [✓](src/main/rust/AoC2023_04/src/main.rs) | | [✓](src/main/rust/AoC2023_06/src/main.rs) | [✓](src/main/rust/AoC2023_07/src/main.rs) | [✓](src/main/rust/AoC2023_08/src/main.rs) | [✓](src/main/rust/AoC2023_09/src/main.rs) | | | | | | [✓](src/main/rust/AoC2023_15/src/main.rs) | [✓](src/main/rust/AoC2023_16/src/main.rs) | [✓](src/main/rust/AoC2023_17/src/main.rs) | [✓](src/main/rust/AoC2023_18/src/main.rs) | | | [✓](src/main/rust/AoC2023_21/src/main.rs) | | [✓](src/main/rust/AoC2023_23/src/main.rs) | | | diff --git a/src/main/python/AoC2023_24.py b/src/main/python/AoC2023_24.py index 3b410a90..f9373261 100644 --- a/src/main/python/AoC2023_24.py +++ b/src/main/python/AoC2023_24.py @@ -81,12 +81,57 @@ def intersection( return ans def part_2(self, input: Input) -> Output2: - return 0 + hs = [] + for line in input: + pp, vv = line.split(" @ ") + pos = Position3D.of(*map(int, pp.split(", "))) + vel = Vector3D.of(*map(int, vv.split(", "))) + hs.append((pos, vel)) + # (DistanceDifference % (RockVelocity-HailVelocity) = 0 + v_x, v_y, v_z = set[int](), set[int](), set[int]() + for hs_a, hs_b in itertools.combinations(hs, 2): + p_a, v_a = hs_a + p_b, v_b = hs_b + if v_a.x == v_b.x and v_a.x != 0: + dp_x = p_a.x - p_b.x + tmp = set[int]() + for v in range(-1000, 1000): + if v != v_a.x and dp_x % (v - v_a.x) == 0: + tmp.add(v) + v_x = v_x | tmp if len(v_x) == 0 else v_x & tmp + if v_a.y == v_b.y and v_a.y != 0: + dp_y = p_a.y - p_b.y + tmp = set[int]() + for v in range(-1000, 1000): + if v != v_a.y and dp_y % (v - v_a.y) == 0: + tmp.add(v) + v_y = v_y | tmp if len(v_y) == 0 else v_y & tmp + if v_a.z == v_b.z and v_a.z != 0: + dp_z = p_a.z - p_b.z + tmp = set[int]() + for v in range(-1000, 1000): + if v != v_a.z and dp_z % (v - v_a.z) == 0: + tmp.add(v) + v_z = v_z | tmp if len(v_z) == 0 else v_z & tmp + if not len(v_x) == len(v_y) == len(v_z) == 1: + raise RuntimeError() + v_r = Vector3D(v_x.pop(), v_y.pop(), v_z.pop()) + p_a, v_a = hs[0] + p_b, v_b = hs[1] + m_a = (v_a.y - v_r.y) / (v_a.x - v_r.x) + m_b = (v_b.y - v_r.y) / (v_b.x - v_r.x) + c_a = p_a.y - (m_a * p_a.x) + c_b = p_b.y - (m_b * p_b.x) + x = int((c_b - c_a) / (m_a - m_b)) + y = int(m_a * x + c_a) + t = (x - p_a.x) // (v_a.x - v_r.x) + z = p_a.z + (v_a.z - v_r.z) * t + return x + y + z @aoc_samples( ( # ("part_1", TEST, 2), - # ("part_2", TEST, "TODO"), + # ("part_2", TEST, 47), ) ) def samples(self) -> None: