Add solutions for day two and three

This commit is contained in:
Danila Fedorin
2022-12-02 23:48:23 -08:00
parent 5c25497318
commit 5f97f44af4
4 changed files with 175 additions and 0 deletions

51
day2.cr Normal file
View File

@@ -0,0 +1,51 @@
require "advent"
INPUT = input(2022, 2).lines.map do |l|
a, b = l.split(" ")
{a, b}
end
WINS1 = {
"AX" => 3 + 1,
"AY" => 6 + 2,
"AZ" => 0 + 3,
"BX" => 0 + 1,
"BY" => 3 + 2,
"BZ" => 6 + 3,
"CX" => 6 + 1,
"CY" => 0 + 2,
"CZ" => 3 + 3,
}
WINS2 = {
"AX" => 0+3,
"AY" => 3+1,
"AZ" => 6+2,
"BX" => 0+1,
"BY" => 3+2,
"BZ" => 6+3,
"CX" => 0+2,
"CY" => 3+3,
"CZ" => 6+1,
}
def part1(input)
input.sum do |x|
a,b = x
WINS1[a+b]
end
end
def part2(input)
input.sum do |x|
a,b = x
WINS2[a+b]
end
end
puts part1(INPUT)
puts part2(INPUT)