Ejemplo n.º 1
0
    else:
        actor = Ship()
    for action, value in instructions:
        if action == 'F':
            actor.forward(value)
        elif action in ('L', 'R'):
            actor.turn(action, value)
        else:
            actor.move(action, value)
    if part2:
        print(actor.ship)
    else:
        print(actor.location)
    return actor.calc_location()


if __name__ == '__main__':
    p = Path(__file__).absolute()
    year = p.parent.stem
    day = int(p.stem.split('y')[1])
    inputs = get_instructions(year, day)

    #     inputs = '''F10
    # N3
    # F7
    # R90
    # F11'''.split('\n')

    print(get_answer(inputs, part2=False))
    print(get_answer(inputs, part2=True))
Ejemplo n.º 2
0
    state[index] = 0
    for _ in range(values):
        index = (index + 1) % n
        state[index] += 1
    return state


@timeit
def get_answer(data, mode):
    states = {}
    state = process_data(data)
    count = 0
    n = len(state)
    while True:
        check = tuple(state)
        if check in states:
            if mode == 'part1':
                return count
            else:
                return count - states[check]
        states[check] = count
        state = run_cycle(state, n)
        count += 1


if __name__ == '__main__':
    day = int(os.path.basename(__file__).split('.')[0].split('y')[1])
    inputs = get_instructions(day)
    print(get_answer(inputs, mode='part1'))
    print(get_answer(inputs, mode='part2'))