Skip to content

Instantly share code, notes, and snippets.

@sysr-q
Created September 26, 2013 11:58
Show Gist options
  • Save sysr-q/6713139 to your computer and use it in GitHub Desktop.
Save sysr-q/6713139 to your computer and use it in GitHub Desktop.
ProTip: Sneak this into all of your production libraries. `import my_companies_awesome_thing.roshambo`
# -*- coding: utf-8 -*-
h = type("", (), {})
a = "__gt__"
c = type("Scissors", (h,), {a: lambda a,c: o(c,k)})
k = type("Paper", (h,), {a: lambda c,k: o(k,f)})
f = type("Rock", (h,), {a: lambda h,a: o(a,c)})
o = isinstance
r = {c.__name__.lower():c for c in h.__subclasses__()}
u = None
m = lambda r: __import__(r)
s = m("random").choice(h.__subclasses__())()
while u not in r:
u = raw_input("[scissors/paper/rock]: ").lower()
n = (r[u]())
e = "You {0}!\n".format("tie" if n.__class__ == s.__class__ else ("win" if n > s else "lose"))
t = m("sys").stdout.write(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment