コード例 #1
0
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]
            if output[0] == '2':
                ox_sys_pos = new_pos
            if new_pos not in visited:
                maze.add_edge(pos, new_pos, weight=1)
                build_recur(new_pos)
            inp = deque([backtrack[move]])
            instr, output, resume, rel_base = intc.parse(
                instr, inp, resume, rel_base)
コード例 #2
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
コード例 #3
0
ファイル: 2019-09.py プロジェクト: scanta2/aocd
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]
コード例 #4
0
ファイル: 2019-07.py プロジェクト: scanta2/aocd
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
import queue
# puzzle = Puzzle(year=2019,day=7)
# program = puzzle.input_data.split('\n')[0]

program = '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'

max_signal = 0

for phase in permutations([0, 1, 2, 3, 4]):
    memory = [deepcopy(program) for i in range(5)]
    resume = [0, 0, 0, 0, 0]
    round = 1
    output = 0
    while any([r != -1 for r in resume]):
        for amplifier in range(5):
            input = deque([str(phase[amplifier]),
                           str(output)]) if round == 1 else deque(
                               [str(output)])
            memory[amplifier], output, resume[amplifier] = intcode2019.parse(
                deepcopy(memory[amplifier]), input, resume[amplifier])
            output = output[0]
        round += 1
    max_signal = max(max_signal, int(output))
puzzle.answer_b = max_signal
コード例 #5
0
ファイル: 2019-13.py プロジェクト: scanta2/aocd
    #     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


コード例 #6
0
ファイル: 2019-05.py プロジェクト: scanta2/aocd
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
from itertools import product
import queue
puzzle = Puzzle(year=2019, day=5)
lines = puzzle.input_data

lines = intcode2019.parse(lines, input='5')
コード例 #7
0
ファイル: 2019-02.py プロジェクト: scanta2/aocd
from aocd.models import Puzzle

from functools import reduce
from operator import xor
import string
import re
from copy import deepcopy
from collections import defaultdict, Counter
from itertools import product
import queue

import intcode2019
puzzle = Puzzle(year=2019, day=2)
lines = puzzle.input_data

for noun, verb in product(range(69, 70), range(100)):
    program = deepcopy(lines)
    tweak = program.split(',')
    tweak[1] = str(noun)
    tweak[2] = str(verb)
    program = ','.join(tweak)
    program = intcode2019.parse(program)

    if program.startswith('19690720'):
        bla = 100 * noun + verb
        break
コード例 #8
0
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])
        if i in queue.keys():
            queue.pop(i)
        intcode[i], output[i], instr_ptr[i], relative_base[i] = intc.parse(
コード例 #9
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)
]
コード例 #10
0
program = """NOT A T
NOT B J
OR T J
NOT C T
OR T J
AND D J
WALK
"""

program2 = """NOT A T
NOT B J
OR T J
NOT C T
OR T J
AND D J
NOT I T
NOT T T
OR F T
AND E T
OR H T
AND T J
AND T J
RUN
"""

inp = deque([str(ord(i)) for i in program2])
output = intc.parse(intcode, input=inp)
# print(output)
print(''.join([chr(int(i)) if int(i) < 255 else i for i in output[-3]]))
puzzle.answer_b = output[-3][-1]
コード例 #11
0
ファイル: 2019-19.py プロジェクト: scanta2/aocd
# 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)])
    computer = intcode2019.convert(instr)