Guest User

Untitled

a guest
Dec 6th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. function count_overclaims(claims)
  2. fabric = zeros(1000, 1000)
  3. for claim in claims
  4. claimed_area = view(
  5. fabric,
  6. claim[:x]+1:claim[:x]+claim[:width],
  7. claim[:y]+1:claim[:y]+claim[:height],
  8. )
  9. claimed_area .+= 1
  10. end
  11. return count(x -> x>1, fabric)
  12. end
  13.  
  14. function parse_claim(s)
  15. id, s = split(s, '@')
  16. corner, dimensions = split(s, ':')
  17. x, y = map(x->parse(Int,x), split(corner, ','))
  18. width, height = map(x->parse(Int,x), split(dimensions, 'x'))
  19. return (x=x, y=y, width=width, height=height)
  20. end
  21.  
  22. println(count_overclaims(map(parse_claim, readlines(stdin))))
Add Comment
Please, Sign In to add comment