Skip to content
loading...

Recursion of lists of numbers

mattsmithies profile image Matt Smithies github logo ・1 min read

Implement a function sum, which will be executed multiple times with n integers. There are 3 levels of difficulty:

Easy

For example:

sum(2,3)() 
result: 5

sum(9,3)() 
result: 12

Medium

For example:

sum(2,3)(1,3)()
result: 9

sum(9,3)(2,2)(1,1,2,1)(9)() 
result: 30

Hard

[Hint] This final challenge, think of solutions that are off the beaten path.

Create a generic case where sum will seemingly have many calls and the parameters for a given execution will always be 1 or more integers.

For example:

sum(2,3)
result: 5

sum(2,3)(1)(2,2)
result: 10

sum(2,3)(1,3)(9,10)
result: 27

sum(9,3)(2,2)(1,1,2,1)(9) 
result: 30

Good luck and have fun!

Matt.

twitter logo DISCUSS
Discussion
markdown guide
Classic DEV Post from Jul 30 '19

When Stack Overflow Goes Offline...

Do you... Get some fresh air Panic...

Matt Smithies profile image
Senior Software Engineer, remote advocate, appreciates kindness.