Created
April 11, 2013 23:14
-
-
Save plaster/5367984 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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