def shift(arr) arr[0] = arr[1] arr[1] = arr[2] arr[2] = arr[3] arr[3] = [] end def push(arr, val) shift(arr) if arr[1] arr[1] << val end if arr[2] arr[2] << val end arr[3] << val end def run(f) increments = 0 buffer = [] f.each do |line| measurement = Integer(line) push(buffer, measurement) if buffer[0] and buffer[1] and buffer[0].length() == 3 and buffer[1].length() == 3 and buffer[1].sum() > buffer[0].sum() increments += 1 end end return increments end