All pastes #1579874 Raw Edit

Serpinski Curve

public python v1 · immutable
#1579874 ·published 2009-09-26 02:49 UTC
rendered paste body
#!/usr/bin/env pythondef top(n,w):    return ["  "*w for _ in xrange(1,w)]+["__"*w] if n == 0 else\    ["%s%s%s"%(" "*(len(t)//2),t," "*(len(t)//2)) for t in top(n-1,w)]+\    ["%s%s"%m for m in zip(left(n-1,w),right(n-1,w))]def left(n,w):    return ["%s/%s"%(" "*i," "*j) for (i,j) in zip(xrange(w-1,-1,-1),xrange(w,w*2))] if n==0 else\    ["%s%s%s"%(" "*(len(t)//2),t," "*(len(t)//2)) for t in right(n-1,w)]+\    ["%s%s"%m for m in zip(top(n-1,w),left(n-1,w))]def right(n,w):    return ["%s\\%s"%(" "*i," "*j) for (j,i) in zip(xrange(w-1,-1,-1),xrange(w,w*2))] if n==0 else\    ["%s%s%s"%(" "*(len(t)//2),t," "*(len(t)//2)) for t in left(n-1,w)]+\    ["%s%s"%m for m in zip(right(n-1,w),top(n-1,w))]def curve(n=0,w=1):    return top(n+1,w)import sysprint "\n".join(x.rstrip() for x in curve(*[int(x) for x in sys.argv[1:]]))