-
Notifications
You must be signed in to change notification settings - Fork 0
/
day09.jl
45 lines (38 loc) · 1.11 KB
/
day09.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
45
using Combinatorics
function number_is_bad(window, number)
!any(x+y == number for (x,y) in combinations(window, 2))
end
@views function part1(data, preample_length)
window_start_idx = 1
for idx in (window_start_idx + preample_length) : length(data)
if number_is_bad(data[window_start_idx:(window_start_idx + preample_length)], data[idx])
return data[idx]
end
window_start_idx += 1
end
0
end
@views function part2(data, number)
for idx in 1:length(data)
set_size = 2
while true
nums = data[idx : (idx + set_size)]
sum_nums = sum(nums)
if sum_nums == number
return minimum(nums) + maximum(nums)
elseif sum_nums > number
break
end
set_size += 1
end
end
end
function main()
data = parse.(Int, readlines("inputs/day09.txt"))
part1_solution = part1(data, 25)
part2_solution = part2(data, part1_solution)
(part1_solution, part2_solution)
end
@time (part1_solution, part2_solution) = main()
@show part1_solution
@show part2_solution