Make a Number

Published by Mubashir Hassan in

In this challenge, you have to find all the subsequences of consecutive numbers that, when their numbers are added between them, are equals to the given number.

Given a positive integer n, implement a function that returns a matrix containing every sequence of consecutive numbers smaller than n, sorted ascendingly by their first term, whose sum is equal to n.

Examples

makeNumber(9) ➞ [ [2, 3, 4], [4, 5] ]

makeNumber(8) ➞ [[]]

makeNumber(100) ➞ [ [9, 10, 11, 12, 13, 14, 15, 16], [18, 19, 20, 21, 22] ]

Notes

If no sequence sum is equal to the given n, return an empty array (see example #2).

Watch a quick demo on how Edabit works.