import sys from queue import Queue import heapq from collections import defaultdict from itertools import permutations from yal.util import * from yal.graph import * from yal.geo2d import * from intcode.intcode import * from aocd import data, submit lines = data.strip().split('\n') #prog = Program(data) keys = set() doors = set() map = [] key_loc = [0] * 27 door_loc = [0] * 26 y = 0 for line in lines: x = 0 map.append(line) for c in line: if c >= 'a' and c <= 'z': key_loc[ord(c) - ord('a')] = Point(x, y) keys.add(c) if c >= 'A' and c <= 'Z': door_loc[ord(c) - ord('A')] = Point(x, y) doors.add(c)
def parse_data(data): return list(map(int, data.strip().split(",")))
import time import networkx as nx from aocd import data t = time.perf_counter() g = nx.Graph(o.strip().split(')') for o in data.strip().split()) print(f"part 1: {sum(nx.shortest_path_length(g, 'COM', o) for o in g.nodes)}") print(f"part 2: {nx.shortest_path_length(g, 'YOU', 'SAN') - 2}") # for directed graph # print(f"part 1: {nx.transitive_closure(g).size()}") # print(f"part 2: {nx.shortest_path_length(g.to_undirected(), 'YOU', 'SAN') - 2}") print(f'done in {time.perf_counter() - t:.2}s')
# m0009 = self.input() # 21: IN (9) # m0009 += 3 # 23: ADD #3, (9), (9) # m0009 *= 3 # 27: MUL #3, (9), (9) # m0009 += 5 # 31: ADD (9), #5, (9) # self.output(m0009) # 35: OUT (9) # self.halted = True # return # 37: HALT if self.ip == 21: self.output((self.input() + 3) * 3 + 5) self.halted = True return True return False prog = [PatchedProgram(data.strip(), i) for i in range(5)] for part in range(2): best = 0 for perm in permutations(range(5 * part, 5 * part + 5)): pipes = [Queue() for p in prog] for i in range(5): prog[i].reset() prog[i].init_io(pipes[i], pipes[(i + 1) % 5]) pipes[i].put(perm[i]) pipes[0].put(0) threaded_executor(prog) best = max(best, prog[4].last_out) print(best)
async def amain(): memory = intcode.init(data.strip().split(',')) t = perf_counter() await run(memory)