import itertools import copy import sys sys.path.append('../..') from util.parsing import parse_list orig = parse_list() ops = copy.deepcopy(orig) print(','.join([str(op) for op in ops])) def f(aa, bb): ops[1] = aa ops[2] = bb i = 0 while i < len(ops): if ops[i] == 99: break a = ops[i+1] b = ops[i+2] c = ops[i+3] if ops[i] == 1: ops[c] = ops[a]+ops[b] i += 4 continue if ops[i] == 2: ops[c] = ops[a]*ops[b] i += 4 continue
#!/usr/bin/env python3 import itertools import math import os import sys sys.path.append('../..') from util.parsing import parse_list, parse_as_str_list, parse_as_str, parse_list2d from functools import reduce from operator import mul if __name__ == "__main__": a = set(parse_list(delim='\n')) b = set(2020 - x for x in a) res = list(a & b) print(res[0] * res[1]) print(reduce(mul, list(filter(lambda x: sum(x) == 2020, itertools.combinations(list(a), 3)))[0], 1))
if (x, y) == (0, 0): sys.stdout.write('@') elif (x, y) == curr_pos: sys.stdout.write('D') elif (x, y) in grid: sys.stdout.write(grid[(x, y)].get('tile')) else: sys.stdout.write(' ') sys.stdout.write('\n') sys.stdout.flush() for y in range(min(ys), max(ys) + 2): up() if __name__ == "__main__": ops = parse_list() computer = IntCode(ops) curr_dir = 1 moves = [] grid = {} curr_pos = (0, 0) grid[curr_pos] = {'tile': EMPTY, 'dist': 0} bfs(computer, curr_dir, curr_pos, grid) print_grid(grid, curr_pos) oxys = filter(lambda x: x[1].get('tile') == OXY, grid.items()) min_dist = sorted(oxys, key=lambda x: x[1].get('dist'))[0] print(min_dist[1].get('dist')) curr_pos = min_dist[0]