-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoC2022_03.jl
51 lines (41 loc) · 953 Bytes
/
AoC2022_03.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
46
47
48
49
50
51
#! /usr/bin/env julia
#
include("aoc_main.jl")
if abspath(PROGRAM_FILE) == @__FILE__
include("aocd.jl")
using .Aocd
end
module AoC2022_03
include("aoc.jl")
function priority(ch::Char)
return islowercase(ch) ? ch - 'a' + 1 : ch - 'A' + 27
end
function part1(input)
return sum(
priority(
first(
intersect(line[1:length(line)÷2], line[length(line)÷2+1:end]),
),
) for line ∈ input
)
end
function part2(input)
return sum(
priority(first(intersect(input[i], input[i+1], input[i+2]))) for
i ∈ 1:3:length(input)
)
end
TEST = @aoc_splitlines("""\
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
""")
function samples()
@assert part1(TEST) == 157
@assert part2(TEST) == 70
end
end # module AoC2022_O3
aoc_main(@__FILE__, ARGS, 2022, 3)