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