From e79b0344fdfe165480715a6c465de396c583112a Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 5 Dec 2020 21:15:22 -0800 Subject: [PATCH] Add initial day6 solution. --- day6.cr | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day6.cr diff --git a/day6.cr b/day6.cr new file mode 100644 index 0000000..df73ee9 --- /dev/null +++ b/day6.cr @@ -0,0 +1,21 @@ +require "advent" +INPUT = input(2020, 6).split("\n\n") + +def part1 + input = INPUT.clone + answers = input.map do |i| + i.chars.uniq!.count &.ascii_letter? + end + puts answers.sum +end + +def part2 + input = INPUT.clone + sol = input.map do |i| + i.split("\n").reject(&.empty?).map(&.chars.to_set).reduce { |s1, s2| s1 & s2 } + end + puts(sol.map(&.size).sum) +end + +part1 +part2