Esempio n. 1
0
def solve_two(boot_code):
    console = Console(boot_code)

    # identify jmp indices
    jmps, nops = [], []
    
    i = 0
    while i < len(console.boot_code):
        instruction = console.boot_code[i]
        if instruction.operation == 'jmp':
            jmps.append(i)
        elif instruction.operation == 'nop':
            nops.append(i)
        i+= 1

    # brute force replace
    for i in (jmps + nops):
        instruction = console.boot_code[i]
        instruction.operation = 'nop 'if i in jmps else 'jmp'
        console.boot_code[i] = instruction

        if console.boot():
            logging.info(f'Accumulator: {console.accumulator}')
            return console.accumulator
        else:
            # reset console
            console.reset()
    return
Esempio n. 2
0
def solve_one(boot_code):
    console = Console(boot_code)    
    console.boot()
    logging.info(f'Accumulator: {console.accumulator}')
    return console.accumulator