Add day 1 solution.

This commit is contained in:
Danila Fedorin 2020-11-30 21:13:12 -08:00
parent 304a009887
commit d2e402bdb8
1 changed files with 27 additions and 0 deletions

27
day1.cr Normal file
View File

@ -0,0 +1,27 @@
INPUT = File.read("day1.txt").lines.map(&.chomp.to_i32)
def part1
input = INPUT.clone
input.each_with_index do |v, i|
input.each_with_index do |v2, j|
next unless v + v2 == 2020 && i != j
puts v*v2
end
end
end
def part2
input = INPUT.clone
input.each_with_index do |v, i|
input.each_with_index do |v2, j|
next if j == i
input.each_with_index do |v3, k|
next if k == j || k == i
puts v3*v2*v if v3 + v2 + v == 2020
end
end
end
end
part1
part2