Skip to content

Instantly share code, notes, and snippets.

@hltbra
Created March 24, 2016 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hltbra/b6bfe9baae0afa77f978 to your computer and use it in GitHub Desktop.
Save hltbra/b6bfe9baae0afa77f978 to your computer and use it in GitHub Desktop.
from galaxy import Galaxy
G = Galaxy([1,2,3,4,5,6]) # creates 6 universes
G.assert_(lambda x: x > 3) # destroys universes 1,2,3
G.assert_(lambda x: x < 6) # destroys universe 6
print(G.all())
print(G.any())
"""
Inspired by https://github.com/karldray/quantum
Create by hltbra
"""
import random
class Galaxy(object):
def __init__(self, universes):
self._universes = universes
def assert_(self, cond):
new_universes = []
for universe in self._universes:
if cond(universe):
new_universes.append(universe)
self._universes = new_universes
def any(self):
return random.choice(self._universes)
def all(self):
return self._universes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment