#JavaScript, 112 bytes var r=[],i=a=b=0 while(a<=x)r.push(a=i++*i/2) for(a=0;a<3;){ b=r[i] if(b<=x){ x-=b a++ console.log(b)} else i--} ###Explanation `x` represents the input `while(a<=x)r.push(a=i++*i/2)` Creates an array of all triangular numbers up to x The `for` loop prints the highest triangular number less than `x`, then subtracts that number from `x`, for three iterations. (basically a greedy algorithm)