Exemplo n.º 1
0
def eval_sequence(commands, start=cards.I, debug=False):
    get = AbstractFunction.create('get', IntValue)
    context = Context(None)
    state = start
    for cmd, side in commands:
        if cmd == cards.get: 
            cmd = get
        if side == 'r':
            state = apply(state, cmd, context)
        else:
            state = apply(cmd, state, context)
        if debug:
            print cmd, side, ':', state
    return state
Exemplo n.º 2
0
from itertools import *
from time import clock
import sys

from rules import cards, AbstractFunction, Error, IntValue, Context, apply
import terms

if __name__ == "__main__":
    part = "1/1"
    if len(sys.argv) > 1:
        part = sys.argv[1]
    our_part, num_parts = map(int, part.split("/"))
    our_part -= 1

    x, y, z, t, r = map(AbstractFunction.create, "XYZTR")
    get = AbstractFunction.create("get", IntValue)

    # desired = set([
    #    'get({0})(get({1}))'.format(i, j)
    #    for i in range(4) for j in range(4)
    #    ])
    desired = set(["numbers"])
    print "search for", desired, "part", part

    allowed_functions = [
        # x, y, z, #t,
        # get,
        cards.zero,
        cards.succ,
        cards.dbl,
        # cards.put, # useless combinator?