From 1c926fc648b412b89e270d2edfd4c48cab720bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 11 Dec 2023 22:33:42 +0100 Subject: aoc11 --- prog/aoc/23/11/1.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ prog/aoc/23/11/in.txt | 10 ++++++++ 2 files changed, 81 insertions(+) create mode 100755 prog/aoc/23/11/1.py create mode 100644 prog/aoc/23/11/in.txt (limited to 'prog/aoc/23') diff --git a/prog/aoc/23/11/1.py b/prog/aoc/23/11/1.py new file mode 100755 index 0000000..ca97d3e --- /dev/null +++ b/prog/aoc/23/11/1.py @@ -0,0 +1,71 @@ +#!/usr/bin/python3 +from sys import argv +if len(argv) != 2: + print(argv[0], "1 # za part one") + print(argv[0], "999999 # za part two") + exit() +def find_all(haystack, needle): + occur = -1 + r = [] + while True: + occur = haystack.find(needle, occur+1) + if occur == -1: + return r + r.append(occur) +galaxies = {} +horizontal_holes = [] +columns = set([]) +linelen = 0 +line = 0 +try: + while True: + s = input() + linelen = len(s) + cols = find_all(s, "#"); + for col in cols: + galaxies[(line, col)] = True + columns |= set([col]) + if len(cols) == 0: + horizontal_holes.append(line) + line += 1 +except EOFError: + pass +lines = line+1 +vertical_holes = [] +for i in range(linelen): + if i not in columns: + vertical_holes.append(i) +horizontal_holes_sums = [] +hhs = 0 +for i in range(lines): + if i in horizontal_holes: + hhs += int(argv[1]) + horizontal_holes_sums.append(hhs) +vertical_holes_sums = [] +vhs = 0 +for i in range(linelen): + if i in vertical_holes: + vhs += int(argv[1]) + vertical_holes_sums.append(vhs) +corr_galaxies = {} +for galaxy in galaxies: + corr_galaxies[(galaxy[0]+horizontal_holes_sums[galaxy[0]], galaxy[1]+vertical_holes_sums[galaxy[1]])] = True +def viscorr(): + for line in range(lines+hhs): + for column in range(linelen+vhs): + if (line, column) in corr_galaxies: + print("#", end="") + else: + print(".", end="") + print() +from itertools import product +pari = {} +for p in product(corr_galaxies, corr_galaxies): + if len(set(p)) == 1: + continue + if (p[0], p[1]) not in pari and (p[1], p[0]) not in pari: + pari[p] = True +s = 0 +for par in pari: + s += abs(par[0][0]-par[1][0])+abs(par[0][1]-par[1][1]) +print(s) diff --git a/prog/aoc/23/11/in.txt b/prog/aoc/23/11/in.txt new file mode 100644 index 0000000..986aad4 --- /dev/null +++ b/prog/aoc/23/11/in.txt @@ -0,0 +1,10 @@ +...#...... +.......#.. +#......... +.......... +......#... +.#........ +.........# +.......... +.......#.. +#...#..... -- cgit v1.2.3