diff options
| author | bthink <bthink@fake.com> | 2025-12-07 15:59:37 +0100 |
|---|---|---|
| committer | bthink <bthink@fake.com> | 2025-12-07 15:59:37 +0100 |
| commit | ed395fe7a7fd68f6db4ea94de8fdcdcb0fac5179 (patch) | |
| tree | 68048caf0328d39083e107cb19b989001389527c /2025 | |
| parent | f6ff66ea2da1f30303f17a2dac341411fb325881 (diff) | |
first week of AOC 2025
Diffstat (limited to '2025')
| -rw-r--r-- | 2025/2025-d01.py | 2 | ||||
| -rw-r--r-- | 2025/aoc2025-d01.py | 20 | ||||
| -rw-r--r-- | 2025/aoc2025-d02.py | 26 | ||||
| -rw-r--r-- | 2025/aoc2025-d03.py | 25 | ||||
| -rw-r--r-- | 2025/aoc2025-d04.py | 31 | ||||
| -rw-r--r-- | 2025/aoc2025-d05.py | 36 | ||||
| -rw-r--r-- | 2025/aoc2025-d06.py | 54 | ||||
| -rw-r--r-- | 2025/aoc2025-d07.py | 56 |
8 files changed, 248 insertions, 2 deletions
diff --git a/2025/2025-d01.py b/2025/2025-d01.py deleted file mode 100644 index f8c5c0b..0000000 --- a/2025/2025-d01.py +++ /dev/null @@ -1,2 +0,0 @@ -#advent of code 2025 -#day 01 diff --git a/2025/aoc2025-d01.py b/2025/aoc2025-d01.py new file mode 100644 index 0000000..f3e9101 --- /dev/null +++ b/2025/aoc2025-d01.py @@ -0,0 +1,20 @@ +#advent of code 2025 +#day 01 + +dial=50; +part1=0; +part2=0; +bigjumps=0; +PuzzleInput=open("01.in","r"); +for instruction in PuzzleInput: + direction=1*(instruction[0]=="R") -1*(instruction[0]=="L"); + jump=int(instruction[1:]); + for step in range(jump): #yes it's bruteforce + dial+=direction; + dial=(100+dial)%100; + if dial==0: + part2+=1; + part1+=dial==0; + +print("part 1",part1); +print("part 2",part2); diff --git a/2025/aoc2025-d02.py b/2025/aoc2025-d02.py new file mode 100644 index 0000000..a35e776 --- /dev/null +++ b/2025/aoc2025-d02.py @@ -0,0 +1,26 @@ +#advent of code 2025 +#day 02 + +part1=0; +part2=0; +PuzzleInput=open("02.in","r").read(); +for IDrange in PuzzleInput.split(","): + IDs=[int(val) for val in IDrange.split("-")]; + for num in range(IDs[0],IDs[1]+1): + strnum=str(num); + numlen=len(strnum); + half=numlen//2; + for step in range(half,0,-1): + sublist=[]; + i=0; + while i < numlen: + substring=strnum[i:i+step]; + sublist.append(substring); + i+=step; + subset=set(sublist); + if len(subset)==1 and sublist.count(sublist[0])==len(sublist): + if step==half and len(sublist)==2: part1+=num; + part2+=num; + break; +print("part 1",part1); +print("part 2",part2); diff --git a/2025/aoc2025-d03.py b/2025/aoc2025-d03.py new file mode 100644 index 0000000..0f315ed --- /dev/null +++ b/2025/aoc2025-d03.py @@ -0,0 +1,25 @@ +#advent of code 2025 +#day 03 +part1=0; +part2=0; + +def joltage(bank,limit): + i=0; + jolt=0; + for bat_ID in range(1-limit,0): + battery=max(bank[:bat_ID]); + i=bank[:bat_ID].index(battery); + bank=bank[i+1:]; + jolt+=battery*(10**(-bat_ID)); + jolt+=max(bank); + return jolt; + +PuzzleInput=open("03.in","r"); +for il,line in enumerate(PuzzleInput): + line=line.replace("\n",""); + bank=[int(c) for c in line]; + part1+=joltage(bank,2); + part2+=joltage(bank,12); + +print("part 1",part1); +print("part 2",part2); diff --git a/2025/aoc2025-d04.py b/2025/aoc2025-d04.py new file mode 100644 index 0000000..46e7578 --- /dev/null +++ b/2025/aoc2025-d04.py @@ -0,0 +1,31 @@ +#advent of code 2025 +#day 04 +part1=0; +part2=0; +wall=set(); +PuzzleInput=open("04.in","r"); +adjacent=[(-1,-1),(0,-1),(1,-1),(-1,0),(1,0),(-1,1),(0,1),(1,1)]; +def IsAccessible(grid,p): + neighbors=0; + px,py=p; + for dx,dy in adjacent: + neighbors+=(px+dx,py+dy) in grid; + return neighbors<4; +#parsing +for y,line in enumerate(PuzzleInput): + for x,c in enumerate(line[:-1]): + if c=="@": wall.add((x,y)); +PuzzleInput.close(); +#solution +while True: + removed=set(); + for pos in wall: + if IsAccessible(wall,pos): + removed.add(pos); + if len(removed)==0: break; + wall.difference_update(removed); + if part1==0: part1+=len(removed); + part2+=len(removed); +#answers +print("part 1",part1); +print("part 2",part2); 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); diff --git a/2025/aoc2025-d06.py b/2025/aoc2025-d06.py new file mode 100644 index 0000000..864cb90 --- /dev/null +++ b/2025/aoc2025-d06.py @@ -0,0 +1,54 @@ +#advent of code 2025 +#day 06 +import re + +def calculate(values,op): + if op=="+": + answer=sum(values); + elif op=="*": + answer=1; + for value in values: + answer*=value; + return answer; + +part1=0; +part2=0; +PuzzleInput=open("06.in","r"); +problems=dict(); +biggerproblems=dict(); +operators=[]; +for y,line in enumerate(PuzzleInput): + line=line.replace("\n",""); + vals=re.findall(r'(\d+|\*|\+)', line); + if y==0: #reserve space for each column + for n in range(len(vals)): + problems[n]=[]; + for n in range(len(line)): + biggerproblems[n]=[]; + for x,val in enumerate(vals): + problems[x].append(val); + if vals.count("+")+vals.count("*")==0: + for x,c in enumerate(line): + biggerproblems[x].append(c); + else: + operators=[op for op in vals]; +PuzzleInput.close(); +#part 1 +for n in problems: + problems[n]=[[int(num) for num in problems[n][:-1]],problems[n][-1]]; + part1+=calculate(*problems[n]); +#part 2 +subproblem=[]; +for n in biggerproblems: + problemline=biggerproblems[n]; + if problemline.count(" ")==len(problemline): + operation=operators.pop(0); + part2+=calculate(subproblem,operation); + subproblem=[]; + continue; + subproblem.append(int("".join(problemline))); +#last column doesn't have it's own whitespace so it's outside the loop +operation=operators.pop(0); +part2+=calculate(subproblem,operation); +print("part 1",part1); +print("part 2",part2); diff --git a/2025/aoc2025-d07.py b/2025/aoc2025-d07.py new file mode 100644 index 0000000..e72effe --- /dev/null +++ b/2025/aoc2025-d07.py @@ -0,0 +1,56 @@ +#advent of code 2025 +#day 07 +part1=0; +part2=0; +#parsing +grid=dict(); +Ymax=0; +Xmax=0; +PuzzleInput=open("07.in","r"); +for y,line in enumerate(PuzzleInput): + Ymax+=1; + for x,c in enumerate(line.replace("\n","")): + grid[(x,y)]=c; + Xmax=max(Xmax,x+1); + if c=="S": + Start=(x,y); + grid[(x,y)]="."; +PuzzleInput.close(); +#solution +total=(0,0); +pathing=dict(); +pathing[total]=set(); +hitBottom=dict(); +splitters=set(); #encountered splitters +beams=set([(Start,total)]); +#recursive search +def findTimelines(point): + if point in hitBottom: + return hitBottom[point]; + hitBottom[point]=0; + for path in pathing[point]: + hitBottom[point]+=findTimelines(path); + return hitBottom[point]; + +for step in range(0,Ymax+1,2): #every 2nd line is empty so i'm skipping it + newbeams=set(); + while beams: + b,prev=beams.pop(); + pathing[prev].add(b); + if b not in pathing: pathing[b]=set(); + bx,by=b; + beam=(bx,by+2); + if grid.get(beam,".")=="^": + splitters.add(beam); + newbeams.add(((bx+1,by+2),(bx,by))); + newbeams.add(((bx-1,by+2),(bx,by))); + else: + newbeams.add(((bx,by+2),(bx,by))); + if by+2>Ymax and b not in hitBottom: + hitBottom[b]=1; #register from which points beams hit the bottom + beams=newbeams; + +part1=len(splitters); +part2=findTimelines(Start); +print("part 1",part1,part1==1533); +print("part 2",part2,part2==10733529153890); |
