def part2(): # mem = flatten(parse("07.txt")) # pp(best_sequence2(mem)) pp( best_sequence2([ 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, ]))
def part1(): numbers = flatten(parse("01.txt")) total = 0 for number in numbers: fuel = number // 3 - 2 pp(number, fuel) total += fuel print(total)
def part2(): mem = flatten(parse("02.txt")) for noun in range(0, 99): for verb in range(0, 99): output = get_output(mem, noun, verb) if output == 19690720: pp(noun, verb, output) pp(100 * noun + verb)
def part1(): mem = flatten(parse("02.txt")) mem[1] = 12 mem[2] = 2 # pp(mem) eip = 0 while eip is not None: eip = step(mem, eip) # pp(eip, mem) pp(mem[0])
def part2(): numbers = list(map(int, open("08.txt").read().strip())) width = 25 height = 6 size = width * height assert len(numbers) % size == 0 image = [2] * width * height for i in range(len(numbers) // size): layer = numbers[i * size:(i + 1) * size] pp(layer) for j in range(size): if image[j] == 2: image[j] = layer[j] pgrid(image, width, height)
def part2(): print("hello") numbers = flatten(parse("01.txt")) total = 0 for number in numbers: subtotal = 0 fuel = number fuel = fuel // 3 - 2 while fuel > 0: subtotal += fuel fuel = fuel // 3 - 2 pp(number, subtotal) total += subtotal print(total)
def part1(): wire1, wire2 = [ line.split(",") for line in open("03-easy.txt").read().strip().splitlines() ][:2] grid = defaultdict(lambda: set()) write(grid, wire1, 1) write(grid, wire2, 2) closest = float('inf') for x, y in grid: if len(grid[(x, y)]) > 1 and (x, y) != (0, 0): pp(x, y, grid[(x, y)]) pp(abs(x) + abs(y)) closest = min(closest, abs(x) + abs(y)) print(closest)
def part2(): wire1, wire2 = [ line.split(",") for line in open("03.txt").read().strip().splitlines() ][:2] grid = defaultdict(lambda: dict()) write2(grid, wire1, 1) write2(grid, wire2, 2) best = float('inf') for x, y in grid: if len(grid[(x, y)]) > 1 and (x, y) != (0, 0): pp(x, y, grid[(x, y)]) val = sum(grid[(x, y)].values()) pp(val) best = min(best, val) print(best) pass
def part1(): orbits = {} planets = set() for line in open("06.txt").read().strip().splitlines(): a, b = line.strip().split(")") orbits[b] = a planets |= {a, b} pp(orbits) pp(planets) total_count = 0 for planet in planets: count = 0 current_planet = planet while current_planet in orbits: current_planet = orbits[current_planet] count += 1 print("%s %s" % (planet, count)) total_count += count print(total_count)
def part2(): siblings = defaultdict(set) planets = set() for line in open("06.txt").read().strip().splitlines(): a, b = line.strip().split(")") siblings[a].add(b) siblings[b].add(a) planets |= {a, b} pp(siblings) pp(planets) queue = deque([("YOU", 0)]) visited = set() while queue: node, steps = queue.popleft() if node == "SAN": pp(steps - 2) return if node in visited: continue visited.add(node) pp(node) for child in siblings[node]: queue.append((child, steps + 1)) print("bad exit")
def part1(): pp( best_sequence( [3, 15, 3, 16, 1002, 16, 10, 16, 1, 16, 15, 15, 4, 15, 99, 0, 0])) pp( best_sequence([ 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, ])) pp( best_sequence([ 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, ])) mem = flatten(parse("07.txt")) pp(best_sequence(mem))