From cba5517ee98a76f1267999baab129b417a1652d2 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 13 Dec 2023 22:00:14 -0800 Subject: [PATCH] [2023][ruby][14.1] --- 2023/ruby/day_14.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 2023/ruby/day_14.rb diff --git a/2023/ruby/day_14.rb b/2023/ruby/day_14.rb new file mode 100644 index 0000000..be5d668 --- /dev/null +++ b/2023/ruby/day_14.rb @@ -0,0 +1,9 @@ +input = ARGF.readlines(chomp: true).map(&:chars) + +p input.transpose + .map {|col| col.chunk_while { [_1, _2].tally.fetch(?#, 0).even? }} + .map {|col| col.flat_map { _1.sort.reverse }} + .transpose + .reverse + .each.with_index + .sum {|row, i| row.count(?O) * (i+1) }