Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2013 17:56
Show Gist options
  • Save anonymous/5365645 to your computer and use it in GitHub Desktop.
Save anonymous/5365645 to your computer and use it in GitHub Desktop.
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
#! /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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment