From 7c1f6ae89c4e5f4296b2548fcdd995a6d621c22f Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Tue, 8 Dec 2020 10:15:46 -0500 Subject: [PATCH] finished solution 2 --- day06/solution02.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 day06/solution02.rb diff --git a/day06/solution02.rb b/day06/solution02.rb new file mode 100755 index 0000000..b3e2a73 --- /dev/null +++ b/day06/solution02.rb @@ -0,0 +1,17 @@ +#!/bin/env ruby + +groups = Hash.new +text = File.read('./input').strip.split("\n\n") + +people = text.map { |t| t.count("\n") + 1 } + +text.map!.with_index do |t, i| + t.delete!("\n") + t.each_char { |c| t.delete!(c) if t.count(c) != people[i] } + t.split('').uniq.reduce(:+) +end + +text.compact! +size = text.map { |t| t.length }.reduce(:+) + +p size \ No newline at end of file