fix aoc helper, add day 2

This commit is contained in:
Patrick Michl
2022-12-02 07:42:26 +01:00
parent 30124c5410
commit 8c7ffecb0b
5 changed files with 2566 additions and 12 deletions

View File

@@ -13,7 +13,8 @@ cals_per_elf() {
((tmp+=i))
done
cals+=("$tmp")
utils.qsort "${cals[@]}"
utils.insertion_sort cals
echo "${cals[@]}"
}
p1() {

43
src/day_2.jl Normal file
View File

@@ -0,0 +1,43 @@
include(joinpath(readchomp(`git rev-parse --show-toplevel`), "aoc.jl"))
import .Aoc: @aoc
win_conditions = Dict(
"A X" => 3,
"A Y" => 6,
"A Z" => 0,
"B X" => 0,
"B Y" => 3,
"B Z" => 6,
"C X" => 6,
"C Y" => 0,
"C Z" => 3,
)
should_play = Dict(
"A X" => 'Z',
"A Y" => 'X',
"A Z" => 'Y',
"B X" => 'X',
"B Y" => 'Y',
"B Z" => 'Z',
"C X" => 'Y',
"C Y" => 'Z',
"C Z" => 'X',
)
score_table = Dict('X' => 1, 'Y' => 2, 'Z' => 3)
function p1(input::Vector{String})
sum([ win_conditions[i] + score_table[i[3]] for i in input ])
end
function transform_input(x)
arr = collect(x)
arr[3] = should_play[x]
join(arr)
end
function p2(input::Vector{String})
input = map(transform_input, input)
sum([ win_conditions[i] + score_table[i[3]] for i in input ])
end
@aoc(2022, 2)