Ruby で作った
nums = <<"EOT".lines( chomp: true ).map( &:to_i ) # 数字の配列。改行は削除
4
7
8
12
15
2
EOT
totals = nums.each_with_object( [ 0 ] ) {
|num, ary| ary.push( ary.last + num ) }
totals.shift # 先頭要素の0 を削除する
p totals #=> [4, 11, 19, 31, 46, 48]