Skip to main content
added explanation
Source Link
ბიმო
  • 16.9k
  • 2
  • 41
  • 104

Husk, 10 bytes

Fż+So:`R0C

Try it online!

Ungolfed/Explanation

             -- implicit inputs n & xs                   | 3  [1,2,3,4]
   S      C  -- cut xs into sublists of length n & ...   | [[1,2,3], [4]]
    (:`R0)   -- ... prepend [0,...,0] (length n)         | [[0,0,0], [1,2,3], [4]]
F            -- accumulate the sublists with             |
 ż+          -- element-wise addition                    | [0+1+4, 0+2, 0+3]

Husk, 10 bytes

Fż+So:`R0C

Try it online!

Husk, 10 bytes

Fż+So:`R0C

Try it online!

Ungolfed/Explanation

             -- implicit inputs n & xs                   | 3  [1,2,3,4]
   S      C  -- cut xs into sublists of length n & ...   | [[1,2,3], [4]]
    (:`R0)   -- ... prepend [0,...,0] (length n)         | [[0,0,0], [1,2,3], [4]]
F            -- accumulate the sublists with             |
 ż+          -- element-wise addition                    | [0+1+4, 0+2, 0+3]
Source Link
ბიმო
  • 16.9k
  • 2
  • 41
  • 104

Husk, 10 bytes

Fż+So:`R0C

Try it online!