In ruby, this is most easily achieved with:
result = input.each_cons(3).map do |left, _, right|
left + right
end
This maps over consecutive three-tuples in `input` and returns empty array for `len(input) < 3`.Edit: nevermind, boundary conditions are still special cases.