fork(1) download
  1. l={}
  2. i=x=y=n=v=0
  3. exec"v+=1;l[y]=l.get(y,'').ljust(x)+`v`;x+=len(`v`);i=-~i%-~n;y+=n%4-1;n+=2>>i*2;"*input()
  4. for k in sorted(l):print l[k]
Success #stdin #stdout 0.02s 9128KB
stdin
40
stdout
                                         26
                                       25  27
         10                          24      28
        9  11                      23          29
 2     8     12                  22              30
1 3   7        13              21                  31
   4 6           14          20                      32
    5              15      19                          33
                     16  18                              34          40
                       17                                  35      39
                                                             36  38
                                                               37