Skip to content

Instantly share code, notes, and snippets.

@nodakai
Forked from anonymous/zigzag.py
Created April 11, 2013 17:59
Show Gist options
  • Save nodakai/5365662 to your computer and use it in GitHub Desktop.
Save nodakai/5365662 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
def prt(x):
i = 0
while i <= x:
if i*(i+1)/2 >= x:
break
i += 1
k = x-(i-1)*i/2
# sys.stdout.write("{:4d}: {}, {}\n".format(x, i, k))
# if i == x-(i-1)*i/2:
# sys.stdout.write("\n")
if 0 == i % 2:
sig = +1
else:
sig = -1
sys.stdout.write("{}{}\n".format(" " * (20 + sig * (k - i / 2)), x))
for i in xrange(50):
prt(i)
@nodakai
Copy link
Author

nodakai commented Apr 11, 2013

                0
               1
                2
                 3
                4
               5
              6
               7
                8
                 9
                  10
                 11
                12
               13
              14
             15
              16
               17
                18
                 19
                  20
                   21
                  22
                 23
                24
               25
              26
             27
            28
             29
              30
               31
                32
                 33
                  34
                   35
                    36
                   37
                  38
                 39
                40
               41
              42
             43
            44
           45
            46
             47
              48
               49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment