summaryrefslogtreecommitdiffstats
path: root/prog
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2023-12-03 12:25:37 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2023-12-03 12:25:37 +0100
commit0cb7a5ced343e31f810992daac0c2a56ce7a3c18 (patch)
tree10511cfe3ad505335538843afd7612ca9c99c58a /prog
parentaoc2 (diff)
downloadr-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar.gz
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar.bz2
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar.lz
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar.xz
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.tar.zst
r-0cb7a5ced343e31f810992daac0c2a56ce7a3c18.zip
Diffstat (limited to 'prog')
-rwxr-xr-xprog/aoc/23/3/1.py45
-rw-r--r--prog/aoc/23/3/in.txt10
2 files changed, 55 insertions, 0 deletions
diff --git a/prog/aoc/23/3/1.py b/prog/aoc/23/3/1.py
new file mode 100755
index 0000000..fce4aa9
--- /dev/null
+++ b/prog/aoc/23/3/1.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python3
+parts = {}
+numbers = []
+ln = 0
+try:
+ while True:
+ l = input() + "."
+ i = 0
+ num = ""
+ for c in l:
+ if not c.isdigit():
+ if num != "":
+ numbers.append((int(num), ln, i-len(num)))
+ num = ""
+ if not c == ".":
+ parts[(ln, i)] = c
+ if c.isdigit():
+ num += c
+ i += 1
+ ln += 1
+except:
+ gears = {}
+ sum = 0
+ sumgears = 0
+ for number in numbers:
+ did = False
+ for char in range(len(str(number[0]))+2):
+ presek = set([(number[1], number[2]-1+char), (number[1]-1, number[2]-1+char), (number[1]+1, number[2]-1+char)]) & set(parts.keys());
+ if len(presek):
+ if not did:
+ sum += number[0]
+ did = True
+ if len(presek) != 1:
+ print("unreachable")
+ part = [x for x in presek][0]
+ if parts[part] == "*":
+ if part not in gears:
+ gears[part] = []
+ gears[part].append(number[0])
+ for pair in gears.values():
+ if len(pair) != 2:
+ continue
+ sumgears += pair[0]*pair[1]
+ print(sum)
+ print(sumgears)
diff --git a/prog/aoc/23/3/in.txt b/prog/aoc/23/3/in.txt
new file mode 100644
index 0000000..b20187f
--- /dev/null
+++ b/prog/aoc/23/3/in.txt
@@ -0,0 +1,10 @@
+467..114..
+...*......
+..35..633.
+......#...
+617*......
+.....+.58.
+..592.....
+......755.
+...$.*....
+.664.598..