コード例 #1
0
ファイル: main.py プロジェクト: lorddusk/AdventOfCode2020
        elif output < final:
            currentList.append(input[numbers])
            numbers += 1

        elif output > final:
            start += 1
            numbers = start + 1
            currentList = [input[start]]

    output = min(currentList) + max(currentList)
    return output


if __name__ == '__main__':
    input = file("day9", 1)
    exampleInput = [
        35, 20, 15, 25, 47, 40, 62, 55, 65, 95, 102, 117, 150, 182, 127, 219,
        299, 277, 309, 576
    ]

    print("Example Part 1")
    check = part1(exampleInput, 5)
    if check == 127:
        print(f"Correct value : {check}")
    else:
        print(f"Incorrect value : {check}")
    print("------------------------------------------------------")

    print("Part 1")
    check = part1(input, 25)
コード例 #2
0
        elif n == 3:
            if len(temp_list) > 3:
                mult_list.append((len(temp_list) - 1) * 2 +
                                 (len(temp_list) - 3))
            elif len(temp_list) > 1:
                mult_list.append((len(temp_list) - 1) * 2)
            temp_list = []

    r2 = 1
    for x in mult_list:
        r2 = r2 * x
    return r2


if __name__ == '__main__':
    input = sorted(file("day10", 1))
    exampleInput = sorted([16, 10, 15, 5, 1, 11, 7, 19, 6, 12, 4])

    exampleInput2 = sorted([
        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
    ])

    print("Example Part 1")
    check = part1(exampleInput, 0)
    check = check.count(1) * check.count(3)
    if check == 35:
        print(f"Correct value : {check}")
    else:
        print(f"Incorrect value : {check}")
コード例 #3
0
ファイル: main.py プロジェクト: lorddusk/AdventOfCode2020
    return i, accu


def _jmp(i, acc):
    i += int(acc)
    return i


def debug(i, tp, accu, step, alreadyChanged):
    print(
        f"Step: {i} - {tp} - Next Step: {i + accu} - Changed: {step} - Loop Changed: {alreadyChanged}"
    )


if __name__ == '__main__':
    input = file("day8")
    exampleInput = [
        "nop +0", "acc +1", "jmp +4", "acc +3", "jmp -3", "acc -99", "acc +1",
        "jmp -4", "acc +6"
    ]

    print("Example Part 1")
    check = part1(exampleInput)
    if check == 5:
        print("Correct value")
    else:
        print("Incorrect value")
    print("------------------------------------------------------")

    print("Part 1")
    check = part1(input)
コード例 #4
0
ファイル: main.py プロジェクト: lorddusk/AdventOfCode2020
            if board[i] == "L":
                max -= math.ceil(diff / 2)
            if board[i] == "R":
                min += math.floor(diff / 2)
        min += 1
        if min == max:
            column = min
        elif board[-3:] == "LLL" and min == 1 and max == 0:
            column = 0
        else:
            print(f"ERROR in COLUMN, {min} - {max}, {board}")
            break
        seatId = row * 8 + column
        if seatId > highestSeatId:
            highestSeatId = seatId
        seatList.append(seatId)
    seatList.sort()
    print(f"Highest ID: {highestSeatId}")
    print(
        f"Missing Seat Id: {sorted(set(range(seatList[0], seatList[-1] + 1)).difference(seatList))[0]}"
    )


if __name__ == '__main__':
    input = file("day5")
    exampleInput = ['FBFBBFFRLR', 'BFFFBBFRRR', 'FFFBBBFRRR', 'BBFFBBFRLL']

    print("PART 1 & 2")
    sortThroughBoardingPasses(input)
    print("------------------------------------------------------")
コード例 #5
0
ファイル: main.py プロジェクト: lorddusk/AdventOfCode2020
        seatY += dy
        key = (seatX, seatY)
        if key not in _seats:
            return '.'

        char = _seats.get(key)
        if char == '.':
            continue
        if char == 'L':
            return 'L'
        if char == '#':
            return '#'


if __name__ == '__main__':
    input = file("day11", 0)
    exampleInput = [
        "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"
    ]

    print("Example Part 1")
    check = part1(exampleInput)
    if check == 37:
        print(f"Correct value : {check}")
    else:
        print(f"Incorrect value : {check}")
    print("------------------------------------------------------")

    print("Part 1")
    check = part1(input)
コード例 #6
0
    groups = [[]] * len(input)
    current = 0
    for line in input:
        if line == "":
            current += 1
        else:
            if groups[current] == []:
                groups[current] = [line]
            else:
                groups[current].append(line)
    filtered = list(filter(None, groups))
    return filtered


if __name__ == '__main__':
    input = file("day6")
    exampleInput = [
        "abc", "", "a", "b", "c", "", "ab", "ac", "", "a", "a", "a", "a", "",
        "b"
    ]

    print("Example Part 1")
    part1(exampleInput)
    print("------------------------------------------------------")
    print("Part 1")
    part1(input)
    print("------------------------------------------------------")
    print("Example Part 2")
    part2(exampleInput)
    print("------------------------------------------------------")
    print("Part 2")
コード例 #7
0
ファイル: main.py プロジェクト: lorddusk/AdventOfCode2020
        sep = bag.find(' bags contain')
        key = bag[:sep]
        contents = bag[sep + 14:]
        bag_instance = []
        if contents[-14:] != 'no other bags.':
            con_list = contents.split(' ')
            for i in range(0, len(con_list), 4):
                bag_num = int(con_list[i])
                bag_type = f'{con_list[i + 1]} {con_list[i + 2]}'
                bag_instance.append([bag_num, bag_type])
        list_to_dict[key] = bag_instance
    return list_to_dict


if __name__ == '__main__':
    input = file("day7")
    exampleInput = ["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.", ]

    print("Example Part 1")
    print(f'The shiny gold bag can go in {len(set(part1(exampleInput, "shiny gold")))} bags.')
    print("------------------------------------------------------")
    print("Part 1")
    print(f'The shiny gold bag can go in {len(set(part1(input, "shiny gold")))} bags.')