Ejemplo n.º 1
0
def compute2(data):
    logging.getLogger().setLevel(logging.INFO)
    painter = Intcode.from_input(data)

    hull_map = defaultdict(lambda: 1)
    position = Point(0, 0)
    direction = Directions.UP

    paint(painter, hull_map, position, direction)

    x_s = [p.x for p in hull_map.keys()]
    y_s = [p.y for p in hull_map.keys()]
    hull_rect = Rectangle(
        left=min(x_s),
        right=max(x_s),
        top=min(y_s),
        bottom=max(y_s),
    )

    out = []
    for y in range(hull_rect.top, hull_rect.bottom + 1):
        line = ''
        for x in range(hull_rect.left, hull_rect.right + 1):
            line += '#' if hull_map[Point(x, y)] == 1 else ' '
        out.append(line)

    return '\n' + '\n'.join(out)
Ejemplo n.º 2
0
def compute(data, noun=12, verb=2):
    code = Intcode.from_input(data)
    code[1] = noun
    code[2] = verb

    code.run()
    return code[0]
Ejemplo n.º 3
0
def compute(data):
    logging.getLogger().setLevel(logging.INFO)
    painter = Intcode.from_input(data)

    hull_map = defaultdict(lambda: 0)
    position = Point(0, 0)
    direction = Directions.UP

    paint(painter, hull_map, position, direction)

    return len(hull_map.items())
Ejemplo n.º 4
0
def test_v(val, expect):
    ex = Intcode(val)
    ex.run()
    assert_that(ex.state, is_(expect))
Ejemplo n.º 5
0
def compute(data):
    code = Intcode.from_input(data)
    code.stdin.append(1)
    code.run()
    return code.stdout
Ejemplo n.º 6
0
def test_v(program, input, output):
    code = Intcode.from_input(program)
    code.stdin.append(input)
    code.run()
    assert_that(code.stdout, is_(output))
Ejemplo n.º 7
0
def compute(data):
    code = Intcode.from_input(data, stdin=[1])
    code.run()
    return code.stdout
Ejemplo n.º 8
0
def compute2(data):
    logging.getLogger().setLevel(logging.INFO)
    code = Intcode.from_input(data, stdin=[2])
    code.run()
    return code.stdout