def second(): def detection(x, y): if x > n and y > n: return True if radar[x - n][y - n:y].count(1) == n and [ m[y - n] for m in radar[x - n:x] ].count(1) == n else False else: return False values = DataAnalyzer.int_csv("2019day19.txt")[0] cpu = Computer.IntCode(values, extend=True, interrupt=False, auto=False, x=25000) done, i, j, size, n = False, 0, 0, 1700, 100 radar = [[0 for i in range(size)] for j in range(size)] for i in range(size): for j in range(size): cpu.reset([i, j]) cpu.start() radar[i][j] = cpu.output()[0] done = detection(i + 1, j + 1) if done: break if done: break print( f"(19.2) LOCATED: {done}, {n}x{n} block at {i-n+1},{j-n+1} :: ship math = {(i-n+1)*10000 + j-n+1}" )
def first(): pattern = (0, 1, 0, -1) print(f"(test) {fft('12345678', pattern, 8, 4)}") print(f"(test) {fft('80871224585914546619083218645595', pattern, 8, 100)[:8]}") print(f"(test) {fft('19617804207202209144916044189917', pattern, 8, 100)[:8]}") sequence = str(DataAnalyzer.load("2019day16.txt")[0]) print(f"(16.1) {fft(sequence, pattern, 8, 100)[:8]}")
def second(): pattern = (0, 1, 0, -1) print(f"(16.2 test) 98765432109876543210, 7 => {'98765432109876543210'[7:7+8]}") sequence = str(DataAnalyzer.load("2019day16.txt")[0]) offset = int(sequence[:7]) sequence += 10000 * sequence signal = fft(sequence, pattern, 8, 10000) print(f"(16.2) {signal[offset:offset+8]}")
def first(): values = DataAnalyzer.int_csv("2019day13.txt")[0] computer = Computer.IntCode(values, extend=True, auto=True) count = 0 output = computer.output() for i in range(0, len(output), 3): count += 1 if output[i+2] == 2 else 0 print(f"(13.1) Block tile count: {count}")
def second(): values = DataAnalyzer.load("2019day1.txt") total = 0 for num in values: running = int(math.floor(int(num) / 3) - 2) while running > 0: total += running running = int(math.floor(int(running) / 3) - 2) print("(1.2) total fuel: {:d}".format(total))
def second(): data = [ "1-3 a: abcde", "1-3 b: cdefg", "2-9 c: ccccccccc" ] print("(2.2.0) test valid passwords is {:d}".format(index_check(data))) data = DataAnalyzer.load("2020day2.txt") print("(2.2) test valid passwords is {:d}".format(index_check(data)))
def first(): data = [ "1-3 a: abcde", "1-3 b: cdefg", "2-9 c: ccccccccc" ] print("(2.1.0) test valid passwords is {:d}".format(bound_check(data))) data = DataAnalyzer.load("2020day2.txt") print("(2.1) valid passwords is {:}".format(bound_check(data)))
def first(): values = DataAnalyzer.load("2019day1.txt") total = 0 for num in [12, 14, 1969, 100756]: print("(test): {:d}".format(calc(num))) for num in values: total += calc(num) print("(1.1) total fuel: {:d}".format(total))
def first(): values = DataAnalyzer.int_csv("2019day19.txt")[0] count = 0 cpu = Computer.IntCode(values, extend=True, interrupt=False, auto=False) for i in range(50): for j in range(50): cpu.reset([i, j]) cpu.start() count += 1 if cpu.output()[0] == 1 else 0 print(f"(19.1) affected points: {count}")
def first(): values = [ 109, 1, 204, -1, 1001, 100, 1, 100, 1008, 100, 16, 101, 1006, 101, 0, 99 ] computer = Computer.IntCode(values, extend=True, auto=True) print(f"(test) {computer.output()}") values = [1102, 34915192, 34915192, 7, 4, 7, 99, 0] computer = Computer.IntCode(values, extend=True, auto=True) print(f"(test) {computer.output()[0]}") values = DataAnalyzer.int_csv("2019day9.txt")[0] computer = Computer.IntCode(values, [1], extend=True, auto=True) print(f"(9.1) {computer.output()[0]}")
def second(): configuration = { 0: 1, 1: 2, 2: 3, 3: 4, 4: 0 } inputs = [3, 26, 1001, 26, -4, 26, 3, 27, 1002, 27, 2, 27, 1, 27, 26, 27, 4, 27, 1001, 28, -1, 28, 1005, 28, 6, 99, 0, 0, 5] sequencer(inputs, configuration, '56789', True) values = DataAnalyzer.int_csv("2019day7.txt")[0] print("(7.2)", end='') sequencer(values, configuration, '56789', True)
def circuitry(puzzle, calculator): wiring = [['R8', 'U5', 'L5', 'D3'], ['U7', 'R6', 'D4', 'L4']] draw("test", 8, 1, 11, wiring, calculator) # 610 wiring = [['R75', 'D30', 'R83', 'U83', 'L12', 'D49', 'R71', 'U7', 'L72'], ['U62', 'R66', 'U55', 'R34', 'D71', 'R55', 'D58', 'R83']] draw("test", 300, 150, 500, wiring, calculator) # 410 wiring = [[ 'R98', 'U47', 'R26', 'D63', 'R33', 'U87', 'L62', 'D20', 'R33', 'U53', 'R51' ], ['U98', 'R91', 'D20', 'R16', 'D67', 'R40', 'U7', 'R15', 'U6', 'R7']] draw("test", 200, 200, 500, wiring, calculator) wiring = DataAnalyzer.str_csv("2019day3.txt") draw(puzzle, 5000, 5000, 40000, wiring, calculator)
def first(): configuration = { 0: 1, 1: 2, 2: 3, 3: 4 } inputs = [3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0] sequencer(inputs, configuration, '01234') inputs = [3, 23, 3, 24, 1002, 24, 10, 24, 1002, 23, -1, 23, 101, 5, 23, 23, 1, 24, 23, 23, 4, 23, 99, 0, 0] sequencer(inputs, configuration, '01234') inputs = [3, 31, 3, 32, 1002, 32, 10, 32, 1001, 31, -2, 31, 1007, 31, 0, 33, 1002, 33, 7, 33, 1, 33, 31, 31, 1, 32, 31, 31, 4, 31, 99, 0, 0, 0] sequencer(inputs, configuration, '01234') print("(7.1) ", end='') inputs = DataAnalyzer.int_csv("2019day7.txt")[0] sequencer(inputs, configuration, '01234')
def second(): data = DataAnalyzer.ints("2020day1.txt") x, y, z = calc3(data) print("(1.2) 2020 {:d} {:d} {:d} => {:d}".format( x, y, z, data[x] * data[y] * data[z]))
def second(): values = DataAnalyzer.int_csv("2019day9.txt")[0] computer = Computer.IntCode(values, [2], extend=True, auto=True) print(f"(9.2) {computer.output()[0]}")
def second(): values = [i.strip() for i in DataAnalyzer.load("2019day22.txt")] deck = repeat_instructions(values) print(f"(22.1) Position of cards 2019 is {deck.index(2020)}")
def first(): values = DataAnalyzer.ints("2020day1.txt") x, y = calc2(values) print("(1.1) 2020 {:d} {:d} => {:d}".format(x, y, values[x] * values[y]))
def first(): values = [i.strip() for i in DataAnalyzer.load("2019day22.txt")] deck = run_instructions(values, [x for x in range(10007)]) print(f"(22.1) Position of cards 2019 is {deck.index(2019)}")
def second(): values = DataAnalyzer.load("2019day14.txt")
def first(): values = DataAnalyzer.int_csv("2019day5.txt")[0] computer = Computer.IntCode(values, [1], auto=True) print(f"(5.1) {computer.output()}")
def second(): values = DataAnalyzer.int_csv("2019day13.txt")[0] codes = play(values.copy()) print(f"(13.2) Final score: {codes}")
def second(): values = DataAnalyzer.int_csv("2019day5.txt")[0] computer = Computer.IntCode(values, [5], auto=True) print(f"(5.2) {computer.output()[0]}")