Exemplo n.º 1
0
def solve():
    file_ = input_.get_input_file(__file__)
    lines = input_.get_lines(file_)

    TREE_KEY = '#'

    # lines = [
    #     '..##.........##.........##.........##.........##.........##.......',
    #     '#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..',
    #     '.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.',
    #     '..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#',
    #     '.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.',
    #     '..#.##.......#.##.......#.##.......#.##.......#.##.......#.##.....',
    #     '.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#',
    #     '.#........#.#........#.#........#.#........#.#........#.#........#',
    #     '#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...',
    #     '#...##....##...##....##...##....##...##....##...##....##...##....#',
    #     '.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#',
    # ]

    diagonal_plot = {
        f'{i+1}-{divmod(i*3, len(l))}': l[i * 3 % len(l)]
        for i, l in enumerate(lines)
    }

    return list(diagonal_plot.values()).count(TREE_KEY)
Exemplo n.º 2
0
def solve():
    results = []
    file_ = input_.get_input_file(__file__)
    lines = input_.get_lines(file_)

    mult = lambda x, y: x * y
    results = [float(i) for i in lines for j in lines if float(i) + float(j) == 2020]
    return int(mult(*results))
Exemplo n.º 3
0
def solve():
    file_ = input_.get_input_file(part1.__file__)
    lines = input_.get_lines(file_)

    # Eh, this is pretty slow.  3 conditionals!
    results = [
        float(i) for i in lines for j in lines for k in lines
        if float(i) + float(j) + float(k) == 2020
    ]
    results = set(results)
    return int(math.prod(results))
Exemplo n.º 4
0
def solve():
    file_ = input_.get_input_file(__file__)
    lines = input_.get_lines(file_)
    # lines = [
    #     '1-3 a: abcde',
    #     '1-3 b: cdefg',
    #     '2-9 c: ccccccccc',
    # ]

    valid_passwords = 0

    for l in lines:
        valid_passwords += 1 if valid_password(Password(l)) else 0

    return valid_passwords
Exemplo n.º 5
0
The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the
preamble) which is not the sum of two of the 25 numbers before it.

What is the first number that does not have this property?

============================================

Your puzzle answer was 104054607.

The first half of this puzzle is complete! It provides one gold star: *

"""
import input_

file_ = input_.get_input_file(__file__)
lines = input_.get_lines(file_)


class Solve:
    PREAMBLE_LEN = 25
    _data = []
    _preamble_work = []
    _limit_reached = False

    def __init__(self, **kwargs):
        for k, v in kwargs:
            setattr(self, k, v) if hasattr(self, k) else None

        self._data = self.parse_data_from_lines(lines)
Exemplo n.º 6
0
def solve():
    file_ = input_.get_input_file(__file__)
    lines = input_.get_lines(file_, newlines=True)
    return [p.validate() for p in lines_to_passports(lines)].count(True)