summaryrefslogtreecommitdiffstats
path: root/prog/aoc/23/11
diff options
context:
space:
mode:
Diffstat (limited to 'prog/aoc/23/11')
-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 @@
+...#......
+.......#..
+#.........
+..........
+......#...
+.#........
+.........#
+..........
+.......#..
+#...#.....