Skip to content

Instantly share code, notes, and snippets.

@plaster
Created April 11, 2013 23:14
Show Gist options
  • Select an option

  • Save plaster/5367984 to your computer and use it in GitHub Desktop.

Select an option

Save plaster/5367984 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
def zigzag(sig, steps):
while True:
yield (sig, steps)
sig *= -1
steps += 1
def locus(x, motion):
i = 0
for (dx, steps) in motion:
for _ in xrange(steps):
yield (x, i)
x += dx
i += 1
# http://d.hatena.ne.jp/odz/20070718/1184769027
def take(n, iterable):
i = 0
for item in iterable:
if i >= n:
break
else:
i += 1
yield item
for (indent, i) in take(50, locus(20, zigzag(-1, 1))):
sys.stdout.write("{}{}\n".format(" " * indent, i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment