From b7e00339a35408ead3e5bb115674d854d6abcdaa Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 12 Dec 2021 21:51:00 -0800 Subject: [PATCH] [2021][ruby][13.x] clean up getting the dir index --- 2021/ruby/day_13.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/2021/ruby/day_13.rb b/2021/ruby/day_13.rb index d9f3f74..4d72242 100644 --- a/2021/ruby/day_13.rb +++ b/2021/ruby/day_13.rb @@ -3,12 +3,9 @@ dots, folds = ARGF.read.split("\n\n") dots = dots.scan(/(\d+),(\d+)/).map { _1.map(&:to_i) } folds = folds.scan(/(x|y)=(\d+)/).map { [_1, _2.to_i] } +dirs = { ?x => 0, ?y => 1 } folds.each do |dir, axis| - index = case dir - when ?x then 0 - when ?y then 1 - else fail - end + index = dirs.fetch(dir) dots.select { _1[index] > axis }.each do |dot| dot[index] = axis - (dot[index] - axis) end