From 6e8f39dbd2896e4b0121a440ebfaa554be102fe6 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 4 Dec 2018 07:02:51 -0800 Subject: [PATCH] [2018][ruby][4.x] refactor, add part one back --- 2018/ruby/day_04.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/2018/ruby/day_04.rb b/2018/ruby/day_04.rb index 2d32a81..36c3732 100644 --- a/2018/ruby/day_04.rb +++ b/2018/ruby/day_04.rb @@ -17,7 +17,13 @@ records.each do |record| end end +# Part One +guard, ranges = stats.max_by {|_,v| v.map(&:size).sum } +minute = ranges.flat_map(&:to_a).group_by {|x| x }.transform_values(&:count).max_by(&:last).first +p guard * minute + +# Part Two guard, (minute, _) = stats.map {|k,v| - [k, v.flat_map(&:to_a).group_by {|x| x }.max_by {|_,v| v.count }] -}.max_by {|_,(_,v)| v.count } + [k, v.flat_map(&:to_a).group_by {|x| x }.transform_values(&:count).max_by(&:last)] +}.max_by {|_,(_,v)| v } p guard * minute