<jupyter_start><jupyter_text>Part 2We only need to tweak the routine slightly to track and remove dead carts<jupyter_code># Read all the carts again
carts = []
for r, line in enumerate(data.splitlines()):
    for c, char in enumerate(line):
        if char in "<>^v":
            cart = Cart(r,c,char,track)
            cart.dead = False
            carts.append(cart)
running = True
tick = -1
while running:
    tick += 1
    carts.sort(key=lambda c: c.pos())
    for cart in carts:
        if not cart.dead:
            cart.drive()

        # Check for colisions
        for other in carts:
            if cart != other and not other.dead and cart.pos() == other.pos():
                cart.dead = True
                other.dead = True
                print("CRASH!", tick, cart.pos()[1], cart.pos()[0])

    carts = [c for c in carts if not c.dead] 
    if len(carts) == 1:
        cart = carts[0]
        print("Last cart standing", cart.pos()[1], cart.pos()[0])
        break<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12450592885375494, 'fraction_numerical': 0.008893280632411068, 'mean_word_length': 2.0978593272171255, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '74163', 'license': 'MIT', 'n_tokens_mistral': 331, 'n_tokens_neox': 318, 'n_words': 103, 'path': 'solutions/2018/kws/13-kws.ipynb', 'repo_name': 'kws/AdventOfCode', 'size': '1012'}