-
Notifications
You must be signed in to change notification settings - Fork 0
/
day04.jl
44 lines (39 loc) · 1.09 KB
/
day04.jl
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
40
41
42
43
44
using BenchmarkTools
function calcPairContains(file)
f = open(file,"r")
c = 0
v = Vector{Int}()
for line in eachline(f)
v = parse.(Int,split(line,[',','-']))
if (v[1]>=v[3] && v[2]<=v[4]) || (v[1]<=v[3] && v[2]>=v[4])
c+=1
end
end
close(f)
return c
end
function calcPairOverlap(file)
f = open(file,"r")
c = 0
v = Vector{Int}()
for line in eachline(f)
v = parse.(Int,split(line,[',','-']))
if (v[1]<=v[4] && v[2]>=v[3])
c+=1
end
end
close(f)
return c
end
@show calcPairContains("day04_test.txt")
@show calcPairContains("day04_input.txt")
@show calcPairOverlap("day04_test.txt")
@show calcPairOverlap("day04_input.txt")
# @show calcBadgePrio("day04_test.txt")
# @show calcPrio("day03_input.txt")
# @show calcBadgePrio("day03_input.txt")
@btime calcPairContains("day04_test.txt");
@btime calcPairContains("day04_input.txt");
@btime calcPairOverlap("day04_test.txt");
@btime calcPairOverlap("day04_input.txt");
# @btime calcBadgePrio("day03_large_input.txt");