#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