Guest User

Untitled

a guest
Dec 12th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. defp largest_global_power(matrix) do
  2. max = {{nil, nil, nil}, nil}
  3.  
  4. Enum.reduce(1..@grid_size, max, fn x, max ->
  5. Enum.reduce(1..@grid_size, max, fn y, max ->
  6. max_size = Enum.min([@grid_size - x, @grid_size - y])
  7.  
  8. Enum.reduce(0..max_size, max, fn s, max ->
  9. square = Matrex.submatrix(matrix, x..(x + s), y..(y + s))
  10. tp = Matrex.sum(square)
  11. {_, max_tp} = max
  12.  
  13. if is_nil(max_tp) or tp > max_tp do
  14. {{x, y, s}, tp}
  15. else
  16. max
  17. end
  18. end)
  19. end)
  20. end)
  21. end
Add Comment
Please, Sign In to add comment