summaryrefslogtreecommitdiff
path: root/2018/aoc2018-d11-p1.py
blob: 2379c3cfa1a2c967f9450fcfbf02d7be4eb18c10 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#advent of code 2018 
#day 11
#part 1

#setup
GridSize = 300;
SquareSize = 3;
fcserialnumber = int(open("input.txt",'r').readline());

testing = False;
#testing = True;
if testing:
	fcserialnumber = 42; #18=>33,45 ; 42 => 21,61;

class fuelcell:
	def __init__(self, x, y, serialnumber):
		self.positionX = x;
		self.positionY = y;
		self.rackID = self.positionX + 10;
		self.powerlevel = self.rackID * self.positionY;
		self.powerlevel += serialnumber;
		self.powerlevel *= self.rackID;
		self.powerlevel = self.powerlevel//100;
		self.powerlevel = self.powerlevel%10;
		self.powerlevel -= 5;
	def coords(self):
		print(f'Fuel Cell coordinates (x,y): {self.positionX},{self.positionY} ');
	def __str__(self):
		return f'{self.powerlevel}';
		
'''
testinput = [[3,5,8],[122,79,57],[217,196,39],[101,153,71]];

for t in testinput:
	dummycell = fuelcell(t[0],t[1],t[2]);
	print(t, " ->  ",dummycell.powerlevel);
	dummycell.coords();
	
print("#############################");
print();
'''

fcgrid = [];
gridline = [];

for Y in range(GridSize):
	gridline.clear();
	for X in range(GridSize):
		gridline.append(fuelcell(X+1,Y+1,fcserialnumber));
	fcgrid.append(gridline.copy());

maxpower = -999; #negative power just to start the algorythm
maxX = 0;
maxY = 0;
powernow = 0;

for Y in range(GridSize-SquareSize+1):
	for X in range(GridSize-SquareSize+1):
		powernow = 0;
		for sy in range(SquareSize):
			for sx in range(SquareSize):
				powernow += fcgrid[Y+sy][X+sx].powerlevel;
		if (powernow > maxpower):
			maxpower = powernow;
			maxX = X;
			maxY = Y;

#print(f'maximum found:  {maxX},{maxY} => {maxpower}');
print("part 1: ");
fcgrid[maxY][maxX].coords();

#10,300 wrong
#9,0 wrong
#0,9 wrong
#33,45