Ejemplo n.º 1
0
import sys
from aoc.input import get_input
from aoc.partselector import part_one, part_two


def inp_decode(x):
    return list(map(int, x.split(',')))


inp = get_input(inp_decode)


class processor(object):
    def __init__(self, lst, tinput):
        self.olst = lst.copy()
        self.olst += [0 for x in range(0, 100)]
        self.tinput = tinput

    opcodes = {
        1: 'opcode1',
        2: 'opcode2',
        3: 'opcode3',
        4: 'opcode4',
        5: 'opcode5',
        6: 'opcode6',
        7: 'opcode7',
        8: 'opcode8',
        99: 'opcode_exit',
        'default': 'opcode_none',
    }
Ejemplo n.º 2
0
from aoc.input import get_input
from aoc.partselector import part_one, part_two, draw
import time
import matplotlib.pyplot as plt


def inpfmt(x):
    return x.split(',')


inp = get_input(inpfmt)


def common_member(a, b):

    a_set = set(a)
    b_set = set(b)

    # check length
    if len(a_set.intersection(b_set)) > 0:
        return (a_set.intersection(b_set))
    else:
        return ("no common elements")


wires = []
for w in inp:
    current = (0, 0)
    coordinates = [current]
    for p in w:
        if p[0] == 'R':
Ejemplo n.º 3
0
from aoc.input import get_input
from aoc.partselector import part_one, part_two

inp = get_input(int)


def calc_amount(value):
    return value // 3 - 2


if part_one():
    sum = 0
    for value in inp:
        result = calc_amount(value)
        sum += result
    print(sum)

if part_two():
    sum = 0
    for value in inp:
        amount = 0
        while True:
            result = calc_amount(value)
            if result <= 0:
                break
            amount += result
            value = result
        sum += amount
    print(sum)
Ejemplo n.º 4
0
from aoc.input import get_input
from aoc.partselector import part_one, part_two


def orbit(x):
    return x.split(')')


inp = get_input(orbit)

orbits = {'COM': None}
for c, o in inp:
    orbits[o] = c

if part_one():
    total = 0
    for o in orbits:
        count = 0
        while orbits[o] is not None:
            count += 1
            o = orbits[o]
        total += count
    print(total)

    pass

if part_two():
    chains = {}
    for o in ['YOU', 'SAN']:
        count = 0
        i = o