summaryrefslogtreecommitdiff
path: root/2025/aoc2025-d05.py
diff options
context:
space:
mode:
authorbthink <bthink@fake.com>2025-12-07 15:59:37 +0100
committerbthink <bthink@fake.com>2025-12-07 15:59:37 +0100
commited395fe7a7fd68f6db4ea94de8fdcdcb0fac5179 (patch)
tree68048caf0328d39083e107cb19b989001389527c /2025/aoc2025-d05.py
parentf6ff66ea2da1f30303f17a2dac341411fb325881 (diff)
first week of AOC 2025
Diffstat (limited to '2025/aoc2025-d05.py')
-rw-r--r--2025/aoc2025-d05.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/2025/aoc2025-d05.py b/2025/aoc2025-d05.py
new file mode 100644
index 0000000..5b9c21c
--- /dev/null
+++ b/2025/aoc2025-d05.py
@@ -0,0 +1,36 @@
+#advent of code 2025
+#day 05
+#p1 elementary school tier iterate over list
+#p2 collapse ranges from input: trims it down by ~50%, that's why part 2 runs first
+#lo1 looks a lot like lol
+part1=0;
+part2=0;
+PuzzleInput=open("05.in","r").read().split("\n\n");
+fresh=[ [int(num) for num in nums.split("-") ] for nums in PuzzleInput[0].split("\n")];
+ingredients=[int(food) for food in PuzzleInput[1].split("\n")];
+#part 2
+changes=True;
+while changes:
+ fresh=sorted(fresh);
+ changes=False;
+ for n1,range1 in enumerate(fresh):
+ lo1,hi1=range1;
+ for n2,range2 in enumerate(fresh):
+ if n1==n2: continue;
+ lo2,hi2=range2;
+ if lo1 in range(lo2,hi2+1) or hi1 in range(lo2,hi2+1):
+ fresh[n1]=[min(lo1,lo2),max(hi1,hi2)];
+ fresh.pop(n2);
+ changes=True;
+ break;
+ if changes: break;
+part2=sum([ranHi+1-ranLo for ranLo,ranHi in fresh]);
+#part 1
+for ingr in ingredients:
+ for lo,hi in fresh:
+ if ingr in range(lo,hi+1):
+ part1+=1;
+ break;
+
+print("part 1",part1);
+print("part 2",part2);