From 7792d82971c76c3f904b568baceced0b21db61b6 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 15 Dec 2015 21:12:18 -0800 Subject: [PATCH] Day 16.1 --- day_16.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/day_16.rb b/day_16.rb index 1871a80..604d4f9 100644 --- a/day_16.rb +++ b/day_16.rb @@ -15,7 +15,15 @@ cars: 2 perfumes: 1 FACTS -puts sues.select {|sue,data| facts.select {|k,_| data.keys.include?(k) }.all? {|k,v| data[k] == v }} +facts_gt = Hash[%w[ cats trees ].map {|k| [k,facts[k]] }] +facts_lt = Hash[%w[ pomeranians goldfish ].map {|k| [k,facts[k]] }] +%w[ cats trees pomeranians goldfish ].each {|k| facts.delete(k) } + +puts sues.select {|sue,data| + facts.select {|k,_| data.keys.include?(k) }.all? {|k,v| data[k] == v } && + facts_gt.select {|k,_| data.keys.include?(k) }.all? {|k,v| data[k] > v } && + facts_lt.select {|k,_| data.keys.include?(k) }.all? {|k,v| data[k] < v } +} __END__ Sue 1: goldfish: 9, cars: 0, samoyeds: 9