integer n = 5 string fmt = sprintf("%%%dd",length(sprintf("%d",n*n-1))) sequence m = repeat(repeat("??",n),n) integer x = 1, y = 1 for d=0 to n*n-1 do m[y][x] = sprintf(fmt,d) if mod(x+y,2) then {x,y} = iff(y1),y+1}:{x+1,y}) else {x,y} = iff(x1)}:{x,y+1}) end if end for for i=1 to n do m[i] = join(m[i]) end for puts(1,join(m,"\n"))