示例#1
0
"""
adventofcode.com
Day 1
https://adventofcode.com/2021/day/1
"""

import fr

inputs: list[int] = list(map(int, fr.read_as_list('input1')))
input_size = len(inputs)

increases: int = 0
for index in range(1, input_size):
    if inputs[index] > inputs[index - 1]:
        increases += 1

print(increases)


def get_window_value(data: list[int], end: int) -> int:
    """Gets the window value of 3 items"""
    return data[end] + data[end - 1] + data[end - 2]


window_increases: int = 0
for index in range(3, input_size):
    if get_window_value(inputs, index) > get_window_value(inputs, index - 1):
        window_increases += 1

print(window_increases)
示例#2
0
"""
adventofcode.com
Day 8
https://adventofcode.com/2021/day/8
"""

import fr

inputs: list[str] = fr.read_as_list('input8')


def part1():
    count: int = 0
    for input in inputs:
        for output in input.split(' ')[-4:]:
            if len(output) == 2 or len(output) == 3 or len(output) == 4 or len(
                    output) == 7:
                count += 1
    print(count)


part1()


def parse_line(line: str):
    _ = line.split(' ')
    encoded_digits = list(map(set, _[0:10]))
    encoded_output = list(map(set, _[-4:]))

    return encoded_digits, encoded_output
示例#3
0
'''
adventofcode.com
Day 18
https://adventofcode.com/2021/day/18
'''

from __future__ import annotations
import re
import fr

INPUTS: list[str] = fr.read_as_list('input18')
SPLITTER = re.compile(r'\d+|\[|\]|,')


def explode(sn: str) -> tuple[str, bool]:
    '''Takes a Snailnumber and explodes it if needed.'''
    e = re.findall(SPLITTER, sn)
    depth: int = 0
    left_idx: int = -1
    right_value: int = -1
    idx: int = 0
    LENGTH = len(e)
    start: int = -1
    end: int = -1
    output = sn
    did_explode: bool = False
    while idx < LENGTH:
        symbol = e[idx]
        if symbol == '[': depth += 1
        elif symbol == ']': depth -= 1
        elif symbol == ',': pass