コード例 #1
0
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """.#.
..#
###"""

    return get_input('17')
コード例 #2
0
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1"""

    return get_input('14')
コード例 #3
0
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """F10
N3
F7
R90
F11"""

    return get_input('12')
コード例 #4
0
ファイル: day11.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """L.LL.LL.LL
LLLLLLL.LL
L.L.L..L..
LLLL.LL.LL
L.LL.LL.LL
L.LLLLL.LL
..L.L.....
LLLLLLLLLL
L.LLLLLL.L
L.LLLLL.LL"""

    return get_input('11')
コード例 #5
0
ファイル: day19.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """0: 4 1 5
1: 2 3 | 3 2
2: 4 4 | 5 5
3: 4 5 | 5 4
4: "a"
5: "b"

ababbb
abbbab
aaabbb
aaaabbb"""

    return get_input('19')
コード例 #6
0
ファイル: day16.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """class: 1-3 or 5-7
row: 6-11 or 33-44
seat: 13-40 or 45-50

your ticket:
7,1,14

nearby tickets:
7,3,47
40,4,50
55,2,20
38,6,12"""

    return get_input('16')
コード例 #7
0
def get_day_input() -> str:
    if os.environ.get('TEST'):
        #         return """16
        # 10
        # 15
        # 5
        # 1
        # 11
        # 7
        # 19
        # 6
        # 12
        # 4"""
        return """28
33
18
42
31
14
46
20
48
47
24
23
49
45
19
38
39
11
1
32
25
35
8
17
7
9
4
2
34
10
3"""

    return get_input('10')
コード例 #8
0
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """35
20
15
25
47
40
62
55
65
95
102
117
150
182
127
219
299
277
309
576"""

    return get_input('9')
コード例 #9
0
    col_repr = seat_repr[7:]
    min_col = 0
    max_col = 7
    for instr in col_repr:
        if instr == 'L':
            max_col = int(max_col - (max_col - min_col + 1) / 2)
        else:
            min_col = int(min_col + (max_col - min_col + 1) / 2)

    return (min_row, min_col)


def seat_id(seat: Tuple[int, int]) -> int:
    return seat[0] * 8 + seat[1]


if __name__ == '__main__':
    input_str = get_input('5')
    seats = map(find_seat, input_str.split('\n'))
    seat_ids = list(map(seat_id, seats))
    id_idx = {id: True for id in seat_ids}
    min_seat_id = min(seat_ids)
    max_seat_id = max(seat_ids)
    for id in range(min_seat_id, max_seat_id):
        if id in id_idx.keys():
            continue
        else:
            print(id)
            break
コード例 #10
0
ファイル: day18.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """1 + (2 * 3) + (4 * (5 + 6))"""

    return get_input('18')
コード例 #11
0
ファイル: day15.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """0,3,6"""

    return get_input('15')
コード例 #12
0

def nb_children(color: str, bag_rules: Dict[str, BagRule]) -> int:
    cnt = 0
    rules = bag_rules[color]
    for child in rules.children:
        nb_child = child[0]
        color_child = child[1]
        cnt += nb_child
        cnt += nb_child * nb_children(color_child, bag_rules)

    return cnt


if __name__ == '__main__':
    input_str = get_input('7')
    # input_str = """light red bags contain 1 bright white bag, 2 muted yellow bags.
    # dark orange bags contain 3 bright white bags, 4 muted yellow bags.
    # bright white bags contain 1 shiny gold bag.
    # muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
    # shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
    # dark olive bags contain 3 faded blue bags, 4 dotted black bags.
    # vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
    # faded blue bags contain no other bags.
    # dotted black bags contain no other bags."""
    bag_rules, parent_indices = parse_rules(input_str)
    # for color, children in bag_rules.items():
    #     print(color, children)
    #
    # print('..............')
    # for color, index in parent_indices.items():
コード例 #13
0
    steps = int(height / slope[1])
    current_position = (0, 0)
    for _i in range(steps - 1):
        current_position = (current_position[0] + slope[0],
                            current_position[1] + slope[1])
        log(str(current_position))
        tree = input_map[current_position[1]][current_position[0] % width]
        log(f'found tree {tree} at [{current_position[0] % width}, {current_position[1]}]'
            )
        nb_trees += tree

    return nb_trees


if __name__ == '__main__':
    input_str = get_input('3')

    mg = MapGrid.from_string(input_str, lambda x: x)
    mg.pretty_print()

    input_map = process_input(input_str)
    display_map(input_map)
    print("""

PART 1

""")
    slope = (3, 1)
    print(count_trees(input_map, slope))
    print("""
コード例 #14
0
    min, max = occurence.split('-')
    letter = letter[0]
    return password.count(letter) >= int(min) and password.count(
        letter) <= int(max)


def validate_password_part2(password_line: str) -> bool:
    positions, letter, password = password_line.split(' ')
    pos1, pos2 = positions.split('-')
    letter = letter[0]
    letter1 = password[int(pos1) - 1]
    letter2 = password[int(pos2) - 1]
    valid = (letter1 == letter
             or letter2 == letter) and not (letter1 == letter2)
    print(f'{valid}  - {password_line}')
    return valid


def count_valid_passwords(passwords: List[str]) -> int:
    cnt = 0
    for password in passwords:
        if validate_password_part2(password):
            cnt += 1

    return cnt


if __name__ == '__main__':
    input_str = get_input('2')
    print(count_valid_passwords(input_str.split('\n')))
コード例 #15
0
ファイル: day1.py プロジェクト: gbataille/AoC_2020
from dataclasses import dataclass, field
from enum import Enum
from typing import List, Set

from utils.input_utils import get_input
from utils.log_utils import log

if __name__ == '__main__':
    input_str = get_input('1')
    input_arr = [int(i) for i in input_str.split('\n')]
    input_arr.sort()
    idx = {key: True for key in input_arr}

    for elem in input_arr:
        comp = 2020 - int(elem)

        for elem2 in input_arr:
            if elem == elem2:
                continue
            if elem2 > comp:
                continue

            comp2 = comp - elem2
            if comp2 in idx.keys():
                print(elem, elem2, comp2)
                print(elem * elem2 * comp2)
                break
コード例 #16
0
from utils.input_utils import get_input
from utils.log_utils import log


def process_input(input_str: str) -> List[Set[str]]:
    groups = []
    group_answers: Optional[Set[str]] = None
    for line in input_str.split('\n'):
        if line == '':
            if group_answers is not None:
                groups.append(list(group_answers))
            group_answers = None
        else:
            if group_answers is None:
                group_answers = set(line)
            else:
                group_answers = group_answers & set(line)
    if group_answers is not None:
        groups.append(list(group_answers))
    return groups


if __name__ == '__main__':
    input_str = get_input('6')
    group_answers = process_input(input_str)
    cnt = 0
    for answers in group_answers:
        cnt += len(list(answers))

    print(cnt)
コード例 #17
0
ファイル: day13.py プロジェクト: gbataille/AoC_2020
def get_day_input() -> str:
    if os.environ.get('TEST'):
        return """939
7,13,x,x,59,x,31,19"""

    return get_input('13')