Skip to content

Instantly share code, notes, and snippets.

@porterjamesj
Last active December 15, 2018 12:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save porterjamesj/75dab49698533ee86e0f7b8354761a31 to your computer and use it in GitHub Desktop.
Save porterjamesj/75dab49698533ee86e0f7b8354761a31 to your computer and use it in GitHub Desktop.
Advent of Code day 3 (https://adventofcode.com/2018/day/3) solution in Julia (https://julialang.org/)
function count_overclaims(claims)
fabric = zeros(1000, 1000)
for claim in claims
claimed_area = view(
fabric,
claim[:x]+1:claim[:x]+claim[:width],
claim[:y]+1:claim[:y]+claim[:height],
)
claimed_area .+= 1
end
return count(x -> x>1, fabric)
end
function parse_claim(s)
id, s = split(s, '@')
corner, dimensions = split(s, ':')
x, y = map(x->parse(Int,x), split(corner, ','))
width, height = map(x->parse(Int,x), split(dimensions, 'x'))
return (x=x, y=y, width=width, height=height)
end
println(count_overclaims(map(parse_claim, readlines(stdin))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment