■ or ■+■ or ■+■+■ or ■+■+■+■ Sum of squares

Goal: Write a given natural number as sum of squares. Thanks to Lagrange, Fermat and Legendre we know that you can write any positive integer as sum of (one), two, three, or maximal four squares of integers.

Your task is to write a program/function which takes a natural number via stdin/argument and outputs/returns a list of one to four numbers, where the sum of the squares of those numbers equals the input number. But you have to find the shortest possible example, that means if you can write a number as three squares, you may not output the four squares version.

Examples:

1 : 1
2 : 1,1
3 : 1,1,1
4 : 2
5 : 1,2
6 : 1,1,2
127 : 1,3,6,9
163 : 1,9,9
1234 : 3,35
1248 : 8,20,28
JavaScript: 141

function x(i){var a=0,b,c,d;for(;a&lt;i;a++)for(b=0;b&lt;i;b++)for(c=0;c&lt;i;c++)for(d=0;d&lt;i;d++)if(a*a+b*b+c*c+d*d==i){console.log(a,b,c,d);return}}