summaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-11 22:33:42 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-11 22:33:42 +0100
commit1c926fc648b412b89e270d2edfd4c48cab720bcb (patch)
tree539a0203e381c27c26046316213bd8a4a9be7062 /prog
parentb (diff)
downloadr-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar.gz
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar.bz2
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar.lz
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar.xz
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.tar.zst
r-1c926fc648b412b89e270d2edfd4c48cab720bcb.zip
Diffstat (limited to 'prog')
-rwxr-xr-xprog/aoc/23/11/1.py71
-rw-r--r--prog/aoc/23/11/in.txt10
2 files changed, 81 insertions, 0 deletions
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 @@
+...#......
+.......#..
+#.........
+..........
+......#...
+.#........
+.........#
+..........
+.......#..
+#...#.....