-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctf.jl
More file actions
39 lines (32 loc) Β· 1004 Bytes
/
Copy pathctf.jl
File metadata and controls
39 lines (32 loc) Β· 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function parse_input(filename)
open(filename, "r") do f
lines = readlines(f)
present_areas = []
regions = []
regions_dim = []
for i β 0:5
p = lines[5*i+2] * lines[5*i+3] * lines[5*i+4]
push!(present_areas, count(c -> c == '#', p))
end
for j β 31:length(lines)
s = split(lines[j], ": ")
push!(regions_dim, parse.(Int, split(s[1], "x")))
push!(regions, parse.(Int, split(s[2])))
end
return present_areas, regions_dim, regions
end
end
function check_region(dim, region, present_areas)
total_area = dim[1] * dim[2]
required_area = 0
for (i, n) β enumerate(region)
required_area += n * present_areas[i]
if required_area > total_area
return 0
end
end
return 1
end
present_areas, regions_dim, regions = parse_input("input.txt")
I = sum(check_region.(regions_dim, regions, (present_areas,)))
println(I)