Decompose a number into triangles Given an integer n, decompose it into a sum of maximal triangular numbers (where Tm represents the mth triangular number, or the sum of the integers from 1 to m) as follows:


while n > 0,


find the largest possible triangular number Tm such that Tm ≤ n.
append m to the triangular-decomposition representation of n.
subtract Tm from n.



For example, an input of 44 would yield an output of 8311, because:


1+2+3+4+5+6+7+8 = 36 &lt; 44, but 1+2+3+4+5+6+7+8+9 = 45 > 44.


the first digit is 8; subtract 36 from 44 to get 8 left over.

1+2+3 = 6 &lt; 8, but 1+2+3+4 = 10 > 8.


the second digit is 3; subtract 6 from 8 to get 2 left over.

1 &lt; 2, but 1+2 = 3 > 2.


the third and fourth digits must be 1 and 1.



Use the digits 1 through 9 to represent the first 9 triangular numbers, then use the letters a through z (can be capitalized or lowercase) to represent the 10th through 35th triangular number. You will never be given an input that will necessitate the use of a larger "digit".

The bounds on the input are 1 ≤ n &lt; 666, and it will always be an integer.

All possible inputs and outputs, and some selected test cases (listed as input, then output):

1 1
2 11
3 2
4 21
5 211
6 3
100 d32
230 k5211
435 t
665 z731


An output of ∞ for an input of -1/12 is not required. :)
JavaScript (ES6), 52 bytes

f=(n,t=0)=&gt;t&lt;n?f(n-++t,t):t.toString(36)+(n?f(n):'')


How?

Rather than explicitly computing Ti&nbsp;=&nbsp;1&nbsp;+&nbsp;2&nbsp;+&nbsp;3&nbsp;+&nbsp;…&nbsp;+&nbsp;i, we start with t&nbsp;=&nbsp;0 and iteratively subtract t&nbsp;+&nbsp;1 from n while t&nbsp;&lt;&nbsp;n, incrementing t at each iteration. When the condition is not fulfilled anymore, a total of Tt has been subtracted from n and the output is updated accordingly. We repeat the process until n&nbsp;=&nbsp;0.

Below is a summary of all operations for n = 100.

 n  |  t | t &lt; n | output
----+----+-------+--------
100 |  0 | yes   | ""
 99 |  1 | yes   | ""
 97 |  2 | yes   | ""
 94 |  3 | yes   | ""
 90 |  4 | yes   | ""
 85 |  5 | yes   | ""
 79 |  6 | yes   | ""
 72 |  7 | yes   | ""
 64 |  8 | yes   | ""
 55 |  9 | yes   | ""
 45 | 10 | yes   | ""
 34 | 11 | yes   | ""
 22 | 12 | yes   | ""
  9 | 13 | no    | "d"
----+----+-------+--------
  9 |  0 | yes   | "d"
  8 |  1 | yes   | "d"
  6 |  2 | yes   | "d"
  3 |  3 | no    | "d3"
----+----+-------+--------
  3 |  0 | yes   | "d3"
  2 |  1 | yes   | "d3"
  0 |  2 | no    | "d32"


Test cases



f=(n,t=0)=&gt;t&lt;n?f(n-++t,t):t.toString(36)+(n?f(n):'')

console.log(f(1))   // 1
console.log(f(2))   // 11
console.log(f(3))   // 2
console.log(f(4))   // 21
console.log(f(5))   // 211
console.log(f(6))   // 3
console.log(f(100)) // d32
console.log(f(230)) // k5211
console.log(f(435)) // t
console.log(f(665)) // z731