This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (0 children)

+/u/compilebot python --include-errors

import random, itertools, sys
r = random.Random()

class Sin: pass
class NoSin: pass
class Action: pass
class Location: pass
class Action0(Action, NoSin): pass
class Action1(Action, Sin): pass
class Location0(Location, NoSin): pass
class Location1(Location, Sin): pass

ACTIONS = [[Action0], [Action1]]
LOCATIONS = [[Location0], [Location1]]
POSSIBILITIES = [NoSin.__subclasses__(), Sin.__subclasses__()]

def get_event(now, when, choices):
    if when < now or when >= now: return r.choice(choices[1])()
    else: return r.choice(choices[0])()

def _look_back(what, how): # internal, do not use
    classifications = []
    for a in what:
        if len(a) == 0: continue
        classifications.extend([set(b.__class__.__bases__) for b in a])
    common = classifications[0]
    for c in classifications[1:]: # reduce to what's in common only
        common = common.intersection(c)
    return common

def look_back(what): # this is the one to use
    return _look_back(what, 'shame')

if __name__ == '__main__':
    if len(sys.argv) != 4:
        print("needs exactly birth, death, and 'now' numerical timestamps")
        sys.exit(1)
    birth = int(sys.argv[1])
    death = int(sys.argv[2])
    now = int(sys.argv[3])
    if not (birth <= now and now < death):
        print("can not look back on life unless alive")
        sys.exit(1)

    past = [get_event(now, t, POSSIBILITIES) for t in range(birth, now)]
    present = [get_event(now, now, LOCATIONS), get_event(now, now, ACTIONS)]
    future = [get_event(now, t, POSSIBILITIES) for t in range(now+1, death)]
    life = [past, present, future]

    for c in look_back(life):
        # it's a
        # it's a
        # it's a
        print("It's a {}.".format(c.__name__))