From ed395fe7a7fd68f6db4ea94de8fdcdcb0fac5179 Mon Sep 17 00:00:00 2001 From: bthink Date: Sun, 7 Dec 2025 15:59:37 +0100 Subject: first week of AOC 2025 --- 2025/aoc2025-d05.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 2025/aoc2025-d05.py (limited to '2025/aoc2025-d05.py') 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); -- cgit v1.2.3