m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/06/b.rb
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:19:04 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-12-25 15:19:04 +0100
commitae26a072fb9d90ad27238ea75004166d17521ed0 (patch)
tree6dca3268466cfc60955304851ef9978d1ff4b768 /06/b.rb
parent8ef384f47d69ce346a523cc76f334b89712e8cab (diff)
Add day 6
Diffstat (limited to '06/b.rb')
-rw-r--r--06/b.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/06/b.rb b/06/b.rb
new file mode 100644
index 0000000..aa29c00
--- /dev/null
+++ b/06/b.rb
@@ -0,0 +1,19 @@
+groups = File.read('input.txt').split("\n\n")
+
+total = groups.reduce(0) do |total, group|
+ answers = group.split("\n")
+
+ all = answers.reduce(Hash.new true) do |all, answer|
+ new_all = {}
+ answer.each_char do |c|
+ if all[c]
+ new_all[c] = true
+ end
+ end
+ new_all
+ end
+ subtotal = all.size
+ total + subtotal
+end
+
+puts total