Skip to content
Onsite

Infinite Curry Sum

MediumP1Coding

Implement sum, an infinitely curried adder.

sum(a) returns a function. Calling that function with numbers adds them to the running total and returns another function. Calling it with no arguments ends the chain and returns the total.

Each call may pass several numbers at once, and calling sum() with no arguments at the start returns 0. Chains must be independent: building one chain must not affect another.

Example 1

Input
sum(1)(2)(3)()
Output
6

Example 2

Input
sum(1, 2)(3, 4)()
Output
10

Example 3

Input
sum()
Output
0

Constraints

  • All arguments are finite numbers
  • A chain can be reused: save a partial chain and continue it twice, each gets its own total

Hints

Run checks the 3 visible tests, Submit all 8.