Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N = 9435; % puzzle input
- P = (mod( floor((ones(300,1)*((1:300)+10)).*((1:300)'*((1:300)+10) + N)/100) , 10) - 5)'; % Power levels
- [maxS,maxX,maxY,maxSquaresize] = deal(-inf,0,0,1);
- for squareSize = 1:300
- for x=1:300-squareSize+1
- for y=1:300-squareSize+1
- s = sum(sum(P(y:y+squareSize-1,x:x+squareSize-1)));
- if s>maxS
- [maxS,maxX,maxY,maxSquaresize]=deal(s,x,y,squareSize);
- end
- end
- end
- end
- disp([maxY,maxX,maxSquaresize])%Part 1(set squareSize=3) + Part 2
Advertisement
Add Comment
Please, Sign In to add comment