Matlab, 44 * 0.5 = 22 === function r=f(n);r=[];for i=1:n;r=[i:n,r];end > f(4) == [4 3 4 2 3 4 1 2 3 4] Javascript, 63 * 0.5 = 31.5 === F=n=>{r=[m=n];while(--n){r=r.slice(0,m-n).concat(n,r)}return r} > F(4) == [ 4, 3, 2, 1, 4, 3, 2, 4, 3, 4 ] Nothing fancy, just concatenating arrays.