<jupyter_start><jupyter_text>Day 1On my trip around the moon, the gravity assist program failed, and I need to figure out what happened to make it work again Part 1Given the intcode, restore the gravity assist program to the "1202 program alarm" state it had just before the last computer caught fire, by building a working intcode computer<jupyter_code>import math
from typing import List
current_intcode = [1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,9,1,19,1,19,6,23,2,6,23,27,2,27,9,31,1,5,31,35,1,35,10,39,2,39,9,43,1,5,43,47,2,47,10,51,1,51,6,55,1,5,55,59,2,6,59,63,2,63,6,67,1,5,67,71,1,71,9,75,2,75,10,79,1,79,5,83,1,10,83,87,1,5,87,91,2,13,91,95,1,95,10,99,2,99,13,103,1,103,5,107,1,107,13,111,2,111,9,115,1,6,115,119,2,119,6,123,1,123,6,127,1,127,9,131,1,6,131,135,1,135,2,139,1,139,10,0,99,2,0,14,0]
original_intcode = [current_intcode[0]] + [12, 2] + current_intcode[3:]
assert len(original_intcode) == len(current_intcode)
def run_opcode(opcode: int, opcode_idx: int, intcode: List[int]) -> List[int]:
    """Given an optcode and it's index in the intcode, perform the operations on the intcode"""
    intcode_idx_1 = intcode[opcode_idx + 1]
    intcode_idx_2 = intcode[opcode_idx + 2]
    intcode_replace_idx = intcode[opcode_idx + 3]
    
    if opcode == 1:
        intcode[intcode_replace_idx] = intcode[intcode_idx_1] + intcode[intcode_idx_2]
    if opcode == 2:
        intcode[intcode_replace_idx] = intcode[intcode_idx_1] * intcode[intcode_idx_2]
    
    return intcode 
assert run_opcode(1, 0, [1,0,0,0,99]) == [2,0,0,0,99]
assert run_opcode(2, 0, [2,3,0,3,99]) == [2,3,0,6,99]
assert run_opcode(2, 0, [2,4,4,5,99,0]) == [2,4,4,5,99,9801]
def run_intcode(intcode: List[int]) -> List[int]:
    """Keep running the optcodes in the intcode until 99 is reached"""
    intcode = intcode.copy()
    opcode_idx = 0
    opcode = intcode[opcode_idx]
    
    while opcode != 99:
        intcode = run_opcode(opcode, opcode_idx, intcode)
        opcode_idx += 4
        opcode = intcode[opcode_idx]
    
    return intcode
assert run_intcode([1,0,0,0,99]) == [2,0,0,0,99]
assert run_intcode([2,3,0,3,99]) == [2,3,0,6,99]
assert run_intcode([2,4,4,5,99,0]) == [2,4,4,5,99,9801]
assert run_intcode([1,1,1,4,99,5,6,0,99]) == [30,1,1,4,2,5,6,0,99]
# Figure out position 0 of the original intcode after it is "compiled"
run_intcode(original_intcode)[0]<jupyter_output><empty_output><jupyter_text>Part 2Time to brute force this sucker! Need to figure out which _noun_ and _verb_ (i.e `intcode[1]` and `intcode[2]`, respectively) produce the output (`intcode[0]`) of 19690720<jupyter_code>from itertools import permutations
# Get all possible noun/verb combos for 0 to 99
noun_verb_combos = list(permutations(range(100), r=2))
idx = -1
output = 0
required_output = 19690720
while output != required_output:
    idx += 1
    intcode = [current_intcode[0]] + list(noun_verb_combos[idx]) + current_intcode[3:]
    output = run_intcode(intcode)[0]
    
noun_verb_combos[idx]   
# Plug these numbers into the magic equation
100 * noun_verb_combos[idx][0] + noun_verb_combos[idx][1]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1595744680851064, 'fraction_numerical': 0.13539651837524178, 'mean_word_length': 5.973033707865168, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '206584', 'license': 'MIT', 'n_tokens_mistral': 1475, 'n_tokens_neox': 1317, 'n_words': 258, 'path': 'day-2.ipynb', 'repo_name': 'pwildenhain/advent-of-code-2019', 'size': '3102'}