[2021][ruby][13.x] refactor

pull/2/head
Alpha Chen 3 years ago
parent 963a61b14e
commit 4d7ad2055f

@ -4,17 +4,13 @@ dots = dots.scan(/(\d+),(\d+)/).map { _1.map(&:to_i) }
folds = folds.scan(/(x|y)=(\d+)/).map { [_1, _2.to_i] } folds = folds.scan(/(x|y)=(\d+)/).map { [_1, _2.to_i] }
folds.each do |dir, axis| folds.each do |dir, axis|
case dir index = case dir
when ?x when ?x then 0
dots.select {|x,y| x > axis }.each do |dot| when ?y then 1
dot[0] = axis - (dot[0] - axis) else fail
end end
when ?y dots.select { _1[index] > axis }.each do |dot|
dots.select {|x,y| y > axis }.each do |dot| dot[index] = axis - (dot[index] - axis)
dot[1] = axis - (dot[1] - axis)
end
else
fail
end end
dots.uniq! dots.uniq!
# p dots.size or exit # p dots.size or exit

Loading…
Cancel
Save