示例#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)
示例#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))
示例#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))
示例#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
示例#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)

    @property
示例#6
0
BBFFBBFRLL: row 102, column 4, seat ID 820.

As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?

To begin, get your puzzle input.

========================================
Your puzzle answer was 978.

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_, newlines=True)

MAX_ROW = 128
MAX_COL = 8

ROW_CHARS = 7
# COL_CHARS = 3

MIN_HALVES = ['F', 'L']
MAX_HALVES = ['B', 'R']


def seat_to_id(line, row_chars):
    row = get_position(line[:row_chars], max_=MAX_ROW)
    col = get_position(line[row_chars:], max_=MAX_COL)
    return (row * 8) + col
示例#7
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)