From 8a74fb8ee7f48d53c1c1b9d3af88b9947beadc89 Mon Sep 17 00:00:00 2001 From: Adrien Abraham Date: Mon, 9 Dec 2019 18:27:55 +0100 Subject: [PATCH] Day 10 --- 2019/day10.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2019/day9.py | 1 - 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 2019/day10.py diff --git a/2019/day10.py b/2019/day10.py new file mode 100644 index 0000000..749bd84 --- /dev/null +++ b/2019/day10.py @@ -0,0 +1,47 @@ +import math + + +def main(): + with open("day10.txt", "rt") as input_file: + amap = [line.rstrip() for line in input_file.readlines()] + + ast_positions = [] + for x, line in enumerate(amap): + for y, value in enumerate(line): + if value == "#": + ast_positions.append((x, y)) + + best_vis = 0 + for pos in ast_positions: + best_vis = max(best_vis, num_visible_asts(ast_positions, pos)) + + print("Best visibility is", best_vis) + +def num_visible_asts(asts, ref): + count = 0 + for ast in asts: + if ast[0] == ref[0] and ast[1] == ref[1]: + continue + if is_visible(asts, ref, ast): + count += 1 + return count + +def is_visible(asts, ref, target): + for ast in asts: + if ast[0] == ref[0] and ast[1] == ref[1]: + continue + if ast[0] == target[0] and ast[1] == target[1]: + continue + if is_on_line(ref, target, ast): + return False + return True + +def is_on_line(a, b, p): + return math.isclose(dist(a, b), dist(a, p) + dist(b, p)) + +def dist(a, b): + return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2) + + +if __name__ == "__main__": + main() diff --git a/2019/day9.py b/2019/day9.py index 982805d..a83db20 100644 --- a/2019/day9.py +++ b/2019/day9.py @@ -9,7 +9,6 @@ EX3 = "104,1125899906842624,99" def main(): with open("day9.txt", "rt") as input_file: text = input_file.readlines()[0].rstrip() - codes = Intcode.parse_input(text) # Part 1