示例#1
0
def part1(game):
    state = intcode.intcode(game.copy())
    grid = {}
    while True:
        outputs = []
        state = intcode.advance(state)
        if state.pos is None:
            break
        outputs.append(state.output.pop())
        state = intcode.advance(state)
        outputs.append(state.output.pop())
        state = intcode.advance(state)
        outputs.append(state.output.pop())
        x, y, tile = outputs
        grid[(x, y)] = tile

    return len([v for v in grid.values() if v == 2])
示例#2
0
 def run(self):
     view = []
     while self.state.pos is not None:
         self.state = intcode.advance(self.state)
         if not self.state.output:
             break
         view.append(self.state.output.pop())
     return ''.join(map(chr, view))
示例#3
0
 def run(self):
     self.state.input.append(ord('n'))
     self.state.input.append(ord('\n'))
     out = []
     while self.state.pos is not None:
         self.state = intcode.advance(self.state)
         while self.state.output:
             out.append(self.state.output.pop(0))
     return out[-1]
示例#4
0
def paint(starting_panel):
    state = intcode.intcode(tape.copy())
    grid = {}
    position = (0, 0)
    facing = directions.N
    grid[position] = starting_panel

    while state.pos is not None:
        color = grid.get(position, 0)
        state.input.append(color)
        state = intcode.advance(state)
        if state.pos is None: break

        paint = state.output.pop()
        grid[position] = paint

        state = intcode.advance(state)
        rotation = state.output.pop()
        position, facing = move(position, facing, rotation)

    return grid
示例#5
0
 def run_with_view(self):
     self.state.input.append(ord('y'))
     self.state.input.append(ord('\n'))
     suffix = '  '
     while self.state.pos is not None:
         self.state = intcode.advance(self.state)
         while self.state.output:
             v = chr(self.state.output.pop(0))
             print(v, end='')
             suffix = suffix[1] + v
             if suffix == '\n\n':
                 time.sleep(0.2)
     return ord(suffix[1])
示例#6
0
    def step(self):
        if not self.state.input:
            return True
        last_direction = self.state.input[0]
        next_pos = vec_add(self.pos, sides[last_direction])

        self.state = intcode.advance(self.state)
        if self.state.pos is None:
            return False
        if not self.state.output:
            return True
        output = self.state.output.pop()
        self.grid[next_pos] = output
        if output == 1:
            self.pos = next_pos
        elif output == 2:
            self.pos = next_pos
            self.oxygen = next_pos
示例#7
0
 def step(self):
     while True:
         outputs = []
         for _ in range(3):
             self.state = intcode.advance(self.state)
             if self.state.pos is None:
                 return False
             if not self.state.output:
                 return True
             outputs.append(self.state.output.pop())
         x, y, value = outputs
         if x == -1 and y == 0:
             self.score = value
             continue
         self.screen[(x, y)] = value
         if value == 3:
             self.paddle = x
         if value == 4:
             self.ball = x
示例#8
0
def check(x, y):
    bot = intcode.intcode(tape.copy())
    bot.input += [x, y]
    bot = intcode.advance(bot)
    return bot.output.pop(0)