|
|
@ -3,12 +3,9 @@ dots, folds = ARGF.read.split("\n\n")
|
|
|
|
dots = dots.scan(/(\d+),(\d+)/).map { _1.map(&:to_i) }
|
|
|
|
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] }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dirs = { ?x => 0, ?y => 1 }
|
|
|
|
folds.each do |dir, axis|
|
|
|
|
folds.each do |dir, axis|
|
|
|
|
index = case dir
|
|
|
|
index = dirs.fetch(dir)
|
|
|
|
when ?x then 0
|
|
|
|
|
|
|
|
when ?y then 1
|
|
|
|
|
|
|
|
else fail
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
dots.select { _1[index] > axis }.each do |dot|
|
|
|
|
dots.select { _1[index] > axis }.each do |dot|
|
|
|
|
dot[index] = axis - (dot[index] - axis)
|
|
|
|
dot[index] = axis - (dot[index] - axis)
|
|
|
|
end
|
|
|
|
end
|
|
|
|