For a given number n
, output an strictly decreasing array whose sum is n
and its lexicographical order is the smallest for any possible outputs
Smallest lexicographical order means that for or sum n=9
the following strictly decreasing arrays are possible: [[9],[8,1],[7,2],[6,3],[5,4],[6,2,1],[5,3,1],[4,3,2]]
. Putting these in lexicographical order: [[4,3,2],[5,3,1],[5,4],[6,2,1],[6,3],[7,2],[8,1],[9]]
, the first [4,3,2]
will be the final output
Testcases
4 -> [3,1]
9 -> [4,3,2]
10 -> [4,3,2,1]
20 -> [6,5,4,3,2]
You may assume that n>0
and that you are allowed to output any human readable form of characters to represent the array of numbers
Note that a strictly decreasing array has no duplicates so the array cannot be [1,1,1...]
This is code-golf, so shortest code wins!