Beispiel #1
0
import networkx as nx
import intcode2019 as intc
from collections import defaultdict, deque, Counter
from aocd.models import Puzzle
from itertools import product, combinations
import string

puzzle = Puzzle(year=2019,day=25)
input_data = puzzle.input_data
computer = intc.convert(input_data)
computer, output, pointer, relative_base = intc.parse(computer,input=deque([]))

commands = """north
take easter egg
east
take astrolabe
south
take space law space brochure
north
west
north
take manifold
north
north
take hologram
north
take weather machine
north
take antenna
south
south
Beispiel #2
0
    #     print(''.join(line))

    if ball_coord_y == paddle_coord_y:
        return '0'
    elif ball_coord_y > paddle_coord_y:
        return '1'
    else:
        return '-1'

    

    


puzzle = Puzzle(year=2019,day=13)
memory = puzzle.input_data.split('\n')
memory = intcode2019.convert(memory[0])
memory[0] = '2'
resume = 0
relative_base = 0
inp = deque([])
while num_blocks > 0:
    memory, output, resume, relative_base = intcode2019.parse(memory,inp,resume, relative_base)
    inp = deque([draw(output)])
    if len(inp) == 0:
        break
    step += 1
puzzle.answer_b = score


Beispiel #3
0
from aocd.models import Puzzle

import intcode2019

from functools import reduce
from operator import xor
import string
import re
from copy import deepcopy
from collections import defaultdict, Counter, deque
from itertools import product, permutations
puzzle = Puzzle(year=2019, day=9)
program = puzzle.input_data

program_intcode = intcode2019.convert(program)
inp = deque(['2'])
# program_intcode = intcode2019.convert('109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99')
# inp = None

new_program, output, curr_instr = intcode2019.parse(program_intcode, inp)
puzzle.answer_b = output[0]
Beispiel #4
0
from collections import defaultdict, deque
from aocd.models import Puzzle
import string

puzzle = Puzzle(year=2019, day=23)
instructions = puzzle.input_data

intcode = [[] for i in range(50)]
output = [[] for i in range(50)]
instr_ptr = [0 for i in range(50)]
relative_base = [0 for i in range(50)]

queue = defaultdict(list)

for i in range(50):
    intcode[i] = intc.convert(instructions)
    inp = deque([str(i)])
    intcode[i], output[i], instr_ptr[i], relative_base[i] = intc.parse(
        intcode[i], input=inp)
    # print(output[i])

nat_y = []
net_idle = 0

while True:
    if len(queue) == 0:
        net_idle += 1
    else:
        net_idle = 0
    for i in range(50):
        inp = deque([-1]) if i not in queue.keys() else deque(queue[i])
Beispiel #5
0
import curses
from curses import wrapper
from aocd.models import Puzzle
import intcode2019
from itertools import product
from collections import deque
puzzle = Puzzle(year=2019, day=17)
instr = puzzle.input_data

intersections = set()

instr = intcode2019.convert(instr)
instr, output, res, base = intcode2019.parse(instr)

camera_output = ''.join([str(chr(int(i))) for i in output]).split('\n')
camera_output = camera_output[0:len(camera_output) - 2]
rows = len(camera_output)
cols = len(camera_output[0])


def find_intersections(x, y):
    dirs = {(1, 0), (-1, 0), (0, 1), (0, -1)}
    if camera_output[y][x] == '#':
        if all([camera_output[y + dir[1]][x + dir[0]] == '#' for dir in dirs]):
            intersections.add((x, y))


[
    find_intersections(x, y) for x in range(1, cols - 1)
    for y in range(1, rows - 1)
]
Beispiel #6
0
import networkx as nx
import intcode2019 as intc
from collections import defaultdict, deque
from aocd.models import Puzzle
import string

puzzle = Puzzle(year=2019, day=21)

intcode_str = puzzle.input_data
intcode = intc.convert(intcode_str)
# program = """NOT A T
# AND D T
# NOT B J
# AND D J
# OR J T
# NOT C J
# AND D J
# OR T J
# RUN
# """

program = """NOT A T
NOT B J
OR T J
NOT C T
OR T J
AND D J
WALK
"""

program2 = """NOT A T
Beispiel #7
0
import networkx as nx
import intcode2019 as intc
from collections import deque
from aocd.models import Puzzle

instr = Puzzle(year=2019, day=15).input_data
instr = intc.convert(instr)
resume = 0
rel_base = 0
maze = nx.Graph()
ox_sys_pos = 0
visited = set()
dirs = {'1': 1j, '2': -1j, '3': -1, '4': 1}
backtrack = {'1': '2', '2': '1', '3': '4', '4': '3'}


def build_recur(pos):
    global visited
    global instr
    global resume
    global rel_base
    global maze
    global ox_sys_pos

    visited.add(pos)
    for move in ['1', '2', '3', '4']:
        inp = deque([move])  # north
        instr, output, resume, rel_base = intc.parse(instr, inp, resume,
                                                     rel_base)
        if output[0] != '0':
            new_pos = pos + dirs[move]
Beispiel #8
0
# start from y at least 100
# find the min x and check that y-99 maxx is in a y-99 maxx+1 is out
# from my previous run I now xmin < y
y = 300
while True:
    if y % 100 == 0:
        print(y)
    xmin = 0
    xmax = y
    while True:
        xtry = (xmax + xmin) // 2
        xtrym1 = xtry - 1

        inp = deque([str(xtry), str(y)])
        computer = intcode2019.convert(instr)
        _, output1, _, _ = intcode2019.parse(computer, inp)
        inp = deque([str(xtrym1), str(y)])
        computer = intcode2019.convert(instr)
        _, output2, _, _ = intcode2019.parse(computer, inp)

        if (output1[0] == '1' and output2[0] == '0'):
            break
        elif output1[0] == '0':
            xmin = xtry
        else:
            xmax = xtry
    inp = deque([str(xtry + 100), str(y - 99)])
    computer = intcode2019.convert(instr)
    _, output1, _, _ = intcode2019.parse(computer, inp)
    inp = deque([str(xtry + 99), str(y - 99)])