Skip to content

Instantly share code, notes, and snippets.

@fathat
Created May 27, 2011 23:12
Show Gist options
  • Save fathat/996372 to your computer and use it in GitHub Desktop.
Save fathat/996372 to your computer and use it in GitHub Desktop.
Infinitely prints fractal triangles using only one root expression and no statements.
(lambda:
not globals().__setitem__('sys', __import__('sys'))
and not globals().__setitem__('this', sys.modules[globals()['__name__']])
and not globals().__setitem__('time', __import__('time'))
and
#program
[setattr(this, k, v) for k,v in {
'set_color': (lambda c: w(['*', ' '][c])),
'abs': (lambda t: (t + (t >> 31)) ^ (t >> 31)),
'w': sys.stdout.write,
'smash': (lambda t: -((t * -1) >> 31)),
'color': (lambda n,k: set_color(smash (k & (n - k)))),
'col': (lambda n, k: k <= n and not color(n,k) and col(n,k + 1)),
'row': (lambda n: not w(' ' * (40-abs(n/2)))
and (col(abs(n), 0) or True)
and not w("\n")
and (abs(n) < 63 or n < 0)
and not time.sleep(0.05)
and row(n+1)),
'triangle': lambda: row(-60) or True and triangle()
}.items() ] and triangle() )()
@randyheydon
Copy link

For compatibility with both Python 2 and 3, on line 14 replace n/2 with n//2.

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