Example #1
0
    def reset(self):
        """ UpdateStateMachin override.

        """
        StateMachine.reset(self)
        if len(self.ctx.orphaned) > 0:
            print "BUG?: Abandoning orphaned requests."
            self.ctx.orphaned.clear()
        self.ctx = ArchiveUpdateContext(self, self.ctx.ui_)
Example #2
0
def amplify(init, program, num):
    machine = StateMachine(operators, program)
    for tpl in perm(range(num)):
        output = init
        for signal in tpl:
            machine.send(signal, output)
            output = next(machine.run())
            machine.reset()
        yield output
Example #3
0
    def reset(self):
        """ StateMachine override. """
        StateMachine.reset(self)

        ctx = UpdateContext(self)
        ctx.repo = self.ctx.repo
        ctx.ui_ = self.ctx.ui_
        ctx.bundle_cache = self.ctx.bundle_cache
        if len(self.ctx.orphaned) > 0:
            print "BUG?: Abandoning orphaned requests."
            self.ctx.orphaned.clear()

        self.ctx = ctx
Example #4
0
    def reset(self):
        """ StateMachine override. """
        StateMachine.reset(self)

        ctx = UpdateContext(self)
        ctx.repo = self.ctx.repo
        ctx.ui_ = self.ctx.ui_
        ctx.bundle_cache = self.ctx.bundle_cache
        if len(self.ctx.orphaned) > 0:
            print "BUG?: Abandoning orphaned requests."
            self.ctx.orphaned.clear()

        self.ctx = ctx
Example #5
0
            grid[pos] = next(painter)
            direction = next(painter) or -1
            orientation = turn(orientation, direction)
            pos = move(*pos, orientation)
        except StopIteration:
            return grid


grid_1 = paints(defaultdict(lambda: 0), (0, 0), 0, robot)


def part_one():
    return len(grid_1)


robot.reset()

grid_2 = paints(defaultdict(lambda: 0, [((0, 0), 1)]), (0, 0), 0, robot)


def plot(grid):
    keys = grid.keys()
    x_max, x_min = max(x for x, y in keys), min(x for x, y in keys)
    y_max, y_min = max(y for x, y in keys), min(y for x, y in keys)
    x_length = abs(x_max - x_min)
    y_length = abs(y_max - y_min)
    x_length, y_length
    graph = np.array([[0] * (x_length + 1)] * (y_length + 1)).transpose()
    for x, y in keys:
        x_i, y_i = x - x_min, y - y_min
        graph[x_i, y_i] = grid[x, y]