From d2e402bdb840f0db127c667f063ee3b0a2ef1d0c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 30 Nov 2020 21:13:12 -0800 Subject: [PATCH] Add day 1 solution. --- day1.cr | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 day1.cr diff --git a/day1.cr b/day1.cr new file mode 100644 index 0000000..78015cb --- /dev/null +++ b/day1.cr @@ -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