Sobes.tech
Junior — Senior

Recursive sum of elements in nested lists

livecode

Task condition

Implement a function f that sums all numeric values found within the passed lists, regardless of their nesting level. The function should accept an arbitrary number of list arguments and return the total sum of all found numbers.

Example usage:

  • Input: f([10, 21, 33], [14, 52], [7, 81, [9, 100]]) Output: 327

  • Input: f([3, [5, 6], 15, [5, 51]], [7, 81, [9, 100]]) Output: 282

  • Input: f([3, [5, [10, 15, [5, 6], 6], 61, [5, 5], 8]]) Output: 129

Note that lists can be nested to an arbitrary depth, and the function should correctly handle any combination of nested and flat lists.