So, to get this on exactly one pass through the array, you need to start at the end by adding one to each element until you press 3, and then start subtracting it.
arr.reverse_each.slice_before(3).flat_map.with_index do |ar,i|
ar.map do |x|
x += 1 if i == 0 unless x == 3
x -= 1 if i == 1
x
end
end.reverse
You can write the inner block much more succinctly, but I like it because this code is simple enough to read as is.
, - , ! (, @sawa, )