summaryrefslogtreecommitdiff
path: root/2025/aoc2025-d12.py
blob: 725144c3bb134f0701fdee5a31fd87225e6babde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#advent of code 2025
#day 12

part1=0;
gifts=[];
trees=[];
ID=None;
PuzzleInput=open("12.in","r");
for line in PuzzleInput:
	line=line.strip();
	if "x" in line:
		dimensions, quantities=line.split(": ");
		dimensions=tuple([int(d) for d in dimensions.split("x")]);
		quantities=[int(q) for q in quantities.split(" ")];
		trees.append((dimensions,quantities));
	elif ID==None:
		ID=int(line.replace(":",""));
		gifts.append([]);
	elif len(line)==0:
		ID=None;
	else:
		gifts[ID].append(list(line));

def validateTree(tree,presents):
	grid,reqs=tree;
	space=grid[0]*grid[1];
	minX,minY=0,0;
	for ID,r in enumerate(reqs):
		pr=presents[ID];
		dimY=max([pr[j].count("#") for j in range(len(pr))]);
		dimX=max( [sum([pr[j][i].count("#") for j in range(len(pr))]) for i in range(len(pr[0]))] );
		minX+=r*dimX;
		minY+=r*dimY;
		space-=r*dimX*dimY;
	return space>0;

for t in trees:
	part1+=1*validateTree(t,gifts);
print("part 1 =",part1);