Exemple #1
0
from aocUtils import loadInputLines, printT
import re

lines = loadInputLines(2020, 7)

bags = {}
for line in lines:
    outerBag = re.search(r'([a-z|\s]+)s contain', line).group(1)
    innerBags = list(
        map(lambda x: (int(x[0]), x[1]),
            re.findall(r'([0-9]+?)\s(.+?bag)', line)))
    bags[outerBag] = innerBags

printT('Bags Parsed')


def containsShinyBag(innerBags):
    for bag in innerBags:
        if bag[1] == 'shiny gold bag' or containsShinyBag(bags[bag[1]]):
            return True
    return False


def part1():
    return sum(containsShinyBag(innerBags) for innerBags in bags.values())


def bagCount(innerBags):
    return sum(bag[0] + bag[0] * bagCount(bags[bag[1]]) for bag in innerBags)

Exemple #2
0
    value = 1
    loopSize = 0
    while value != publicKey:
        value = (value * subjectNumber) % 20201227
        loopSize += 1
    return loopSize


def transform(subjectNumber, loopSize):
    value = 1
    for _ in range(0, loopSize):
        value = (value * subjectNumber) % 20201227
    return value


def part1():
    cardLoopSize = getLoopSize(cardPublicKey, 7)
    return transform(doorPublicKey, cardLoopSize)


def part2():
    return


assert getLoopSize(5764801, 7) == 8
assert getLoopSize(17807724, 7) == 11
assert transform(17807724, 8) == 14897079
assert transform(5764801, 11) == 14897079

printT(part1())
printT(part2())
        monstersInner = 0
        for point in map:
            if containsMonster(map, point):
                monstersInner += 1
        if monsters > monstersInner:
            total = 0
            for point in map:
                if map.get(point, '.') != '.':
                    total += 1
        monsters = max(monsters, monstersInner)
         
    total = total - monsters * 15
    
    return total

lines = loadInputLines(2020, 20)

tiles = {}
tile = ''
for line in lines:
    if line.startswith('Tile'):
        tile = line.split(' ')[1][:-1]
        tiles[tile] = []
    elif len(line) > 0:
        tiles[tile].append(line)
tiles = [(int(tile), getTilePermutations(tiles[tile])) for tile in tiles]

printT('Finished parsing input')
map = getSolution(tiles)
printT(part1(map))
printT(part2(map))