Guest User

Untitled

a guest
Dec 11th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.54 KB | None | 0 0
  1. N       = 9435; % puzzle input
  2. P       = (mod( floor((ones(300,1)*((1:300)+10)).*((1:300)'*((1:300)+10) + N)/100) , 10) - 5)'; % Power levels
  3. [maxS,maxX,maxY,maxSquaresize] = deal(-inf,0,0,1);
  4. for squareSize = 1:300
  5.     for x=1:300-squareSize+1
  6.         for y=1:300-squareSize+1
  7.             s = sum(sum(P(y:y+squareSize-1,x:x+squareSize-1)));
  8.             if s>maxS
  9.                 [maxS,maxX,maxY,maxSquaresize]=deal(s,x,y,squareSize);
  10.             end
  11.         end
  12.     end
  13. end
  14. disp([maxY,maxX,maxSquaresize])%Part 1(set squareSize=3) + Part 2
Advertisement
Add Comment
Please, Sign In to add comment