Esempio n. 1
0
File: day2.py Progetto: trallard/AoC
The address of the current instruction is called the instruction pointer; it starts at 0. After an instruction finishes, the instruction pointer increases by the number of values in the instruction; until you add more instructions to the computer, this is always 4 (1 opcode + 3 parameters) for the add and multiply instructions. (The halt instruction would increase the instruction pointer by 1, but it halts the program instead.)

"With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need to determine what pair of inputs produces the output 19690720."

The inputs should still be provided to the program by replacing the values at addresses 1 and 2, just like before. In this program, the value placed in address 1 is called the noun, and the value placed in address 2 is called the verb. Each of the two input values will be between 0 and 99, inclusive.

Once the program has halted, its output is available at address 0, also just like before. Each time you try a pair of inputs, make sure you first reset the computer's memory to the values in the program (your puzzle input) - in other words, don't reuse memory from a previous attempt.

Find the input noun and verb that cause the program to produce the output 19690720. What is 100 * noun + verb? (For example, if noun=12 and verb=2, the answer would be 1202.)
"""

import pytest
import aoc

# Getting the input for the puzzle
helper = aoc.puzzle_data(year=2019, day=2)
x = helper.get_data().strip().split(",")  # so that we have a list of numbers
memory = list(map(int, x))


##############################################################################
# Part 1
##############################################################################
def decode(codes):
    pos = 0
    codes[1] = 12
    codes[2] = 2
        if codes[pos] == 1:
            pos1, pos2, res = codes[pos + 1], codes[pos + 2], codes[pos + 3]
            codes[res] = codes[pos1] + codes[pos2]
            pos += 4
Esempio n. 2
0
"""
@trallard
Advent of Code 2017: Day 10
"""

import aoc
# Getting the input for the puzzle
helper = aoc.puzzle_data(year = 2017, day = 12)

# Note that for this one I donwloaded the input and
# worked on the train
file = open('./inputs/17_input5.txt')
connect = {}
for line in file:
    line = line.strip().split()
    connect[line[0]] = [x.strip(',') for x in line[2:]]

seen = set()
def find_pipes(progr):
    if progr in seen:
        return
    seen.add(progr)
    for x in connect[progr]:
        find_pipes(x)


#find_pipes('0')
#print('Part 1: {}'.format(len(seen)))


seen = set()
Esempio n. 3
0
File: day1.py Progetto: trallard/AoC
"""
@trallard
Advent of Code 2018
title: "Day 1: Chronal Calibration"
"""
import pytest
import aoc

# Getting the input for the puzzle
helper = aoc.puzzle_data(year=2018, day=1)
x = helper.get_data().strip().split()  # so that we have a list of numbers
freq = list(map(int, x))


##############################################################################
# Part 1
##############################################################################
def freq1(freq):
    return sum(freq)


print(f"Part 1: {freq1(freq)}")


##############################################################################
# Part 2
##############################################################################
def freq_repeat(freq):
    uniques = set()
    count = 0
    while True: