diff options
author | b-idea <test@test.com> | 2023-09-28 13:25:01 +0200 |
---|---|---|
committer | b-idea <test@test.com> | 2023-09-28 13:25:01 +0200 |
commit | c1fdc53e46d456d6bfa4f5a416a1e58e8a6468ef (patch) | |
tree | 4ce8a0fec0fff5bb9fafb89546d195eca81c006f /2018/aoc2018-d11-p1.py | |
parent | 3d1bbf7d8f051a8b8c8473cac699a91f8e87dfda (diff) |
added days: 10,11,12,14,16,18
Diffstat (limited to '2018/aoc2018-d11-p1.py')
-rwxr-xr-x | 2018/aoc2018-d11-p1.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/2018/aoc2018-d11-p1.py b/2018/aoc2018-d11-p1.py new file mode 100755 index 0000000..2379c3c --- /dev/null +++ b/2018/aoc2018-d11-p1.py @@ -0,0 +1,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
|