From cc99caf9c2308f2d1d6d9cd9a2dc2b7bcc38f34d Mon Sep 17 00:00:00 2001 From: felixm Date: Sat, 9 Dec 2023 09:56:22 -0500 Subject: [PATCH] Do day 14 and 15. --- README.md | 4 +- d14.py | 104 +++++++++++++++++++++++++++++++++++ d15.py | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++ i14.txt | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ i15.txt | 40 ++++++++++++++ lib.py | 4 +- 6 files changed, 460 insertions(+), 3 deletions(-) create mode 100644 d14.py create mode 100644 d15.py create mode 100644 i14.txt create mode 100644 i15.txt diff --git a/README.md b/README.md index d1f5e2e..aec3045 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,6 @@ - Day 11: 45:00 and 18:00 for leaderboard; arg, it was doable man - Day 12: 39:45 and 9:46 for leaderboard; the people are ready for there searches :D - Day 13: 44:00 and 12:56 for leaderboard; these people are just good, seriously -- Day 14: +- Day 14: 35:00 and 14:54; I just have to get that much quicker... 2D code! +- Day 15: 150:00 and 27:00; I didn't use Manhatten dist initially, lot's of debugging +- Day 16: diff --git a/d14.py b/d14.py new file mode 100644 index 0000000..53258fa --- /dev/null +++ b/d14.py @@ -0,0 +1,104 @@ +import lib + +EXAMPLE = """ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 +""" + +def solve(lines: list[str]): + c = set() + for (i, line) in enumerate(lines): + coords = [list(map(int, c.split(","))) for c in line.split(" -> ")] + for i in range(len(coords) - 1): + a, b = coords[i:i + 2] + a_x, a_y = a + b_x, b_y = b + if a_x == b_x and a_y < b_y: + for y in range(a_y, b_y + 1): + c.add((a_x, y)) + elif a_x == b_x and a_y > b_y: + for y in range(b_y, a_y + 1): + c.add((a_x, y)) + elif a_y == b_y and a_x < b_x: + for x in range(a_x, b_x + 1): + c.add((x, a_y)) + elif a_y == b_y and a_x > b_x: + for x in range(b_x, a_x + 1): + c.add((x, a_y)) + else: + raise Exception(f"unexpected {a=} {b=}") + + largest_y = max(c, key=lambda c: c[1])[1] + s = (500, 0) + s_count = 0 + while s[1] < largest_y: + if not (ns := (s[0], s[1] + 1)) in c: + s = ns + elif not (ns := (s[0] - 1, s[1] + 1)) in c: + s = ns + elif not (ns := (s[0] + 1, s[1] + 1)) in c: + s = ns + else: + c.add(s) + s = (500, 0) + s_count += 1 + return s_count + +def solve2(lines: list[str]): + c = set() + for (i, line) in enumerate(lines): + coords = [list(map(int, c.split(","))) for c in line.split(" -> ")] + for i in range(len(coords) - 1): + a, b = coords[i:i + 2] + a_x, a_y = a + b_x, b_y = b + if a_x == b_x and a_y < b_y: + for y in range(a_y, b_y + 1): + c.add((a_x, y)) + elif a_x == b_x and a_y > b_y: + for y in range(b_y, a_y + 1): + c.add((a_x, y)) + elif a_y == b_y and a_x < b_x: + for x in range(a_x, b_x + 1): + c.add((x, a_y)) + elif a_y == b_y and a_x > b_x: + for x in range(b_x, a_x + 1): + c.add((x, a_y)) + else: + raise Exception(f"unexpected {a=} {b=}") + + largest_y = max(c, key=lambda c: c[1])[1] + for x in range(-10000, 10000): + c.add((x, largest_y + 2)) + + s = (500, 0) + s_count = 1 + while True: + if not (ns := (s[0], s[1] + 1)) in c: + s = ns + elif not (ns := (s[0] - 1, s[1] + 1)) in c: + s = ns + elif not (ns := (s[0] + 1, s[1] + 1)) in c: + s = ns + elif s[1] == 0: + return s_count + else: + c.add(s) + s_count += 1 + s = (500, 0) + +def main(): + lines = lib.str_to_lines_no_empty(EXAMPLE) + print("Example 1:", solve(lines)) + + lines = lib.str_to_lines_no_empty(open("i14.txt").read()) + print("Solution 1:", solve(lines)) + + lines = lib.str_to_lines_no_empty(EXAMPLE) + print("Example 2:", solve2(lines)) + + lines = lib.str_to_lines_no_empty(open("i14.txt").read()) + print("Solution 2:", solve2(lines)) + +if __name__ == "__main__": + main() diff --git a/d15.py b/d15.py new file mode 100644 index 0000000..a465a0b --- /dev/null +++ b/d15.py @@ -0,0 +1,151 @@ +import lib +import math + +EXAMPLE = """ +Sensor at x=2, y=18: closest beacon is at x=-2, y=15 +Sensor at x=9, y=16: closest beacon is at x=10, y=16 +Sensor at x=13, y=2: closest beacon is at x=15, y=3 +Sensor at x=12, y=14: closest beacon is at x=10, y=16 +Sensor at x=10, y=20: closest beacon is at x=10, y=16 +Sensor at x=14, y=17: closest beacon is at x=10, y=16 +Sensor at x=8, y=7: closest beacon is at x=2, y=10 +Sensor at x=2, y=0: closest beacon is at x=2, y=10 +Sensor at x=0, y=11: closest beacon is at x=2, y=10 +Sensor at x=20, y=14: closest beacon is at x=25, y=17 +Sensor at x=17, y=20: closest beacon is at x=21, y=22 +Sensor at x=16, y=7: closest beacon is at x=15, y=3 +Sensor at x=14, y=3: closest beacon is at x=15, y=3 +Sensor at x=20, y=1: closest beacon is at x=15, y=3 +""" + +def unify_ranges(ranges): + # aaaaaaaaaaa + # bbbb + # + # aaa + # bbb + # + # aaa + # bbb + ranges = sorted(ranges) + while True: + for i in range(len(ranges) - 1): + a, b = ranges[i], ranges[i + 1] + if a == b: + del ranges[i] + break + elif a[0] == b[0]: + ranges[i] = (a[0], max(a[1], b[1])) + del ranges[i + 1] + break + elif a[1] == b[1]: + ranges[i] = (min(a[0], b[0]), b[1]) + del ranges[i + 1] + break + elif a[0] < b[0] and a[1] > b[1]: + del ranges[i + 1] + break + elif a[0] > b[0] and a[1] < b[1]: + del ranges[i] + break + elif a[1] < b[0]: + pass + elif a[0] <= b[1] and a[1] >= b[0]: + ranges[i] = (a[0], b[1]) + del ranges[i + 1] + break + else: + raise Exception("uhoh", a, b) + else: + return ranges + return ranges + +def mdist(dx, dy): + return abs(dx) + abs(dy) + +def xdist(dm, dy): + x = dm - abs(dy) + if x <= 0: + return 0 + return x + +def solve(lines: list[str], yt): + sensors = [] + bacons = set() + for (i, line) in enumerate(lines): + digits = lib.str_to_int_list(line) + sx, sy, bx, by = digits + sm = mdist(bx - sx, by - sy) + sensors.append([sx, sy, sm]) + bacons.add((bx, by)) + + ranges = [] + for (sx, sy, sm) in sensors: + x_range = xdist(sm, yt - sy) + if x_range == 0: + continue + r = (sx - x_range, sx + x_range) + # print(f"{sx=} {sy=} {r=}") + ranges.append(r) + + ranges = unify_ranges(ranges) + r = 0 + for (a, b) in ranges: + r += b - a + 1 + for (bx, by) in list(bacons): + if by == yt and bx >= a and bx <= b: + r -= 1 + # 140:00 I don't know what a Manhattan distance is. + return r + +def solve2(lines: list[str], xymax): + sensors = [] + bacons = set() + for (i, line) in enumerate(lines): + digits = lib.str_to_int_list(line) + sx, sy, bx, by = digits + sm = mdist(bx - sx, by - sy) + sensors.append([sx, sy, sm]) + bacons.add((bx, by)) + + finds = [] + for yt in range(0, xymax): + ranges = [] + for (sx, sy, sm) in sensors: + x_range = xdist(sm, yt - sy) + if x_range == 0: + continue + r = (sx - x_range, sx + x_range) + ranges.append(r) + ranges = unify_ranges(ranges) + + if ranges[0][0] > 0: + raise Exception("Bacon at 0.") + elif ranges[-1][-1] < xymax: + raise Exception("Bacon at xymax.") + + for i in range(len(ranges) - 1): + if ranges[i + 1][0] - ranges[i][1] > 1: + finds.append((ranges[i][1] + 1, yt)) + if len(finds) != 1: + raise Exception("TOO MANY FINDS") + else: + x, y = finds[0] + return x * 4000000 + y + # 10:00 + +def main(): + lines = lib.str_to_lines_no_empty(EXAMPLE) + print("Example 1:", solve(lines, 10)) + + lines = lib.str_to_lines_no_empty(open("i15.txt").read()) + print("Solution 1:", solve(lines, 2000000)) + + lines = lib.str_to_lines_no_empty(EXAMPLE) + print("Example 2:", solve2(lines, 20)) + + lines = lib.str_to_lines_no_empty(open("i15.txt").read()) + print("Solution 2:", solve2(lines, 4000000)) + +if __name__ == "__main__": + main() diff --git a/i14.txt b/i14.txt new file mode 100644 index 0000000..299ca42 --- /dev/null +++ b/i14.txt @@ -0,0 +1,160 @@ +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +481,79 -> 485,79 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +493,85 -> 497,85 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +499,85 -> 503,85 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +482,107 -> 487,107 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +496,82 -> 500,82 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +489,148 -> 489,149 -> 501,149 -> 501,148 +482,49 -> 487,49 +488,24 -> 488,25 -> 499,25 -> 499,24 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +489,148 -> 489,149 -> 501,149 -> 501,148 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,82 -> 482,82 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +493,79 -> 497,79 +471,52 -> 476,52 +469,58 -> 474,58 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +469,103 -> 469,104 -> 484,104 -> 484,103 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +479,29 -> 489,29 -> 489,28 +475,85 -> 479,85 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +490,76 -> 494,76 +486,109 -> 491,109 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +489,49 -> 494,49 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +488,24 -> 488,25 -> 499,25 -> 499,24 +476,58 -> 481,58 +476,111 -> 481,111 +490,82 -> 494,82 +483,111 -> 488,111 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +488,24 -> 488,25 -> 499,25 -> 499,24 +479,56 -> 484,56 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +473,113 -> 478,113 +480,113 -> 485,113 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +481,85 -> 485,85 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +490,111 -> 495,111 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +468,54 -> 473,54 +484,76 -> 488,76 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +483,58 -> 488,58 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +465,56 -> 470,56 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +481,45 -> 486,45 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +494,113 -> 499,113 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +489,148 -> 489,149 -> 501,149 -> 501,148 +472,56 -> 477,56 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +475,54 -> 480,54 +485,47 -> 490,47 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +484,82 -> 488,82 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +462,58 -> 467,58 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +487,113 -> 492,113 +487,73 -> 491,73 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +505,129 -> 505,131 -> 504,131 -> 504,135 -> 517,135 -> 517,131 -> 509,131 -> 509,129 +469,103 -> 469,104 -> 484,104 -> 484,103 +487,79 -> 491,79 +479,29 -> 489,29 -> 489,28 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +487,85 -> 491,85 +475,49 -> 480,49 +479,109 -> 484,109 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +469,103 -> 469,104 -> 484,104 -> 484,103 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +485,42 -> 485,41 -> 485,42 -> 487,42 -> 487,38 -> 487,42 -> 489,42 -> 489,32 -> 489,42 -> 491,42 -> 491,33 -> 491,42 -> 493,42 -> 493,34 -> 493,42 +498,13 -> 498,16 -> 496,16 -> 496,20 -> 509,20 -> 509,16 -> 502,16 -> 502,13 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +468,98 -> 468,96 -> 468,98 -> 470,98 -> 470,90 -> 470,98 -> 472,98 -> 472,90 -> 472,98 -> 474,98 -> 474,92 -> 474,98 -> 476,98 -> 476,97 -> 476,98 -> 478,98 -> 478,97 -> 478,98 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 +494,61 -> 494,63 -> 490,63 -> 490,70 -> 499,70 -> 499,63 -> 498,63 -> 498,61 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,47 -> 483,47 +500,138 -> 500,142 -> 498,142 -> 498,146 -> 513,146 -> 513,142 -> 506,142 -> 506,138 +493,126 -> 493,123 -> 493,126 -> 495,126 -> 495,117 -> 495,126 -> 497,126 -> 497,123 -> 497,126 -> 499,126 -> 499,122 -> 499,126 -> 501,126 -> 501,119 -> 501,126 -> 503,126 -> 503,125 -> 503,126 -> 505,126 -> 505,122 -> 505,126 +478,162 -> 478,154 -> 478,162 -> 480,162 -> 480,159 -> 480,162 -> 482,162 -> 482,156 -> 482,162 -> 484,162 -> 484,161 -> 484,162 -> 486,162 -> 486,155 -> 486,162 -> 488,162 -> 488,159 -> 488,162 -> 490,162 -> 490,158 -> 490,162 -> 492,162 -> 492,159 -> 492,162 -> 494,162 -> 494,158 -> 494,162 -> 496,162 -> 496,153 -> 496,162 diff --git a/i15.txt b/i15.txt new file mode 100644 index 0000000..e663ca5 --- /dev/null +++ b/i15.txt @@ -0,0 +1,40 @@ +Sensor at x=1112863, y=496787: closest beacon is at x=1020600, y=2000000 +Sensor at x=2980210, y=1712427: closest beacon is at x=2946825, y=1712605 +Sensor at x=2799204, y=1425283: closest beacon is at x=2946825, y=1712605 +Sensor at x=3999908, y=2754283: closest beacon is at x=4064129, y=2651511 +Sensor at x=760990, y=1455625: closest beacon is at x=1020600, y=2000000 +Sensor at x=3996490, y=3239979: closest beacon is at x=4064129, y=2651511 +Sensor at x=3347352, y=3603589: closest beacon is at x=3621840, y=3614596 +Sensor at x=2888433, y=2337157: closest beacon is at x=2946825, y=1712605 +Sensor at x=3423261, y=2191958: closest beacon is at x=3153728, y=1862250 +Sensor at x=1160237, y=3999960: closest beacon is at x=109153, y=3585462 +Sensor at x=693519, y=3701289: closest beacon is at x=109153, y=3585462 +Sensor at x=2615270, y=2824808: closest beacon is at x=2554122, y=2935074 +Sensor at x=3046971, y=1755494: closest beacon is at x=2946825, y=1712605 +Sensor at x=139591, y=1186912: closest beacon is at x=1020600, y=2000000 +Sensor at x=2309134, y=47090: closest beacon is at x=3211831, y=-792661 +Sensor at x=1849154, y=1377259: closest beacon is at x=2946825, y=1712605 +Sensor at x=2515971, y=2851853: closest beacon is at x=2554122, y=2935074 +Sensor at x=2524614, y=2738138: closest beacon is at x=2554122, y=2935074 +Sensor at x=3811778, y=1370280: closest beacon is at x=3153728, y=1862250 +Sensor at x=2615590, y=3819371: closest beacon is at x=2554122, y=2935074 +Sensor at x=3996286, y=3719213: closest beacon is at x=3621840, y=3614596 +Sensor at x=3963152, y=2368927: closest beacon is at x=4064129, y=2651511 +Sensor at x=3495504, y=3076982: closest beacon is at x=3621840, y=3614596 +Sensor at x=3725521, y=2560764: closest beacon is at x=4064129, y=2651511 +Sensor at x=952643, y=2385401: closest beacon is at x=1020600, y=2000000 +Sensor at x=3934384, y=2596106: closest beacon is at x=4064129, y=2651511 +Sensor at x=3060628, y=3082730: closest beacon is at x=2554122, y=2935074 +Sensor at x=3468382, y=3916817: closest beacon is at x=3621840, y=3614596 +Sensor at x=3300107, y=469364: closest beacon is at x=3211831, y=-792661 +Sensor at x=2306388, y=1932261: closest beacon is at x=2946825, y=1712605 +Sensor at x=1965, y=3514070: closest beacon is at x=109153, y=3585462 +Sensor at x=3081537, y=1841861: closest beacon is at x=3153728, y=1862250 +Sensor at x=2997643, y=1729779: closest beacon is at x=2946825, y=1712605 +Sensor at x=21714, y=3624181: closest beacon is at x=109153, y=3585462 +Sensor at x=1549467, y=3109269: closest beacon is at x=2554122, y=2935074 +Sensor at x=3722307, y=3839410: closest beacon is at x=3621840, y=3614596 +Sensor at x=3848580, y=3544878: closest beacon is at x=3621840, y=3614596 +Sensor at x=1189516, y=2153239: closest beacon is at x=1020600, y=2000000 +Sensor at x=468190, y=1889204: closest beacon is at x=1020600, y=2000000 +Sensor at x=270403, y=2762568: closest beacon is at x=109153, y=3585462 diff --git a/lib.py b/lib.py index 6e4715b..b256614 100644 --- a/lib.py +++ b/lib.py @@ -2,13 +2,13 @@ import re def str_to_single_int(line: str) -> int: line = line.replace(" ", "") - r = re.compile(r"\d+") + r = re.compile(r"-?\d+") for m in r.findall(line): return int(m) raise Exception("No single digit sequence in '{line}'") def str_to_int_list(line: str) -> list[int]: - r = re.compile(r"\d+") + r = re.compile(r"-?\d+") return list(map(int, r.findall(line))) def str_to_lines_no_empty(text: str) -> list[str]: