Пример #1
0
from collections import Counter
from collections import defaultdict
import sys
sys.path.append('..')
from data_handler import write_input, write_output  # noqa

DAY = '14'

input_file = write_input(DAY)

# READ
rules = {}
polymerTemplate = None
with open(input_file, 'r') as f:
    for i, line in enumerate(f.read().splitlines()):
        if i == 0:
            polymerTemplate = line
        elif line != '':
            parts = line.split(' -> ')
            rules[parts[0]] = parts[1]


class PolymerNode:
    def __init__(self, val):
        self.val = val
        self.next = None


def createPolymer(template):
    root = PolymerNode(None)
    head = root
Пример #2
0
G: 769 (increased)
H: 792 (increased)

In this example, there are 5 sums that are larger than the previous sum.

Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum?

'''
from collections import deque
import sys
sys.path.append('..')
from data_handler import write_input, write_output  # noqa

DAY = '1'

input_file = write_input('1')

# READ
data = None
with open(input_file, 'r') as f:
    data = [int(line) for line in f.read().splitlines()]

# SOLUTION 1
solution_1 = 0
for i in range(1, len(data)):
    if data[i] > data[i-1]:
        solution_1 += 1

# SOLUTION 2
solution_2 = 0
sums = deque()