Exemplo n.º 1
0
from collections import defaultdict
from aoc import get_input_as, submit


inp = get_input_as(int, sep=',')

lanternfish = defaultdict(int)
triggers = defaultdict(list)

for i in inp:
    lanternfish[i + 1] += 1
counter = len(inp)

for i in range(1, 256 + 1):
    if i in lanternfish:
        counter += lanternfish[i]
        lanternfish[i + 7] += lanternfish[i]
        lanternfish[i + 9] += lanternfish[i]
        del lanternfish[i]

submit(counter)
Exemplo n.º 2
0
from collections import Counter
from aoc import get_input_as

inp = get_input_as(str)
bit_count = len(inp[0])

candidates = list(inp)
for bit_index in range(bit_count):
    counter = Counter([x[bit_index] for x in candidates])
    # o2 gen
    most_common_bit = counter.most_common()[0][0]
    if counter.most_common()[0][1] == counter.most_common()[1][1]:
        most_common_bit = '1'

    old_candidates = list(candidates)
    candidates = []
    for val in old_candidates:
        if val[bit_index] == most_common_bit:
            candidates.append(val)

    if len(candidates) == 1:
        o2_gen = int(candidates[0], 2)
        break

candidates = list(inp)
for bit_index in range(bit_count):
    # co2 scrubber
    counter = Counter([x[bit_index] for x in candidates])
    least_common_bit = counter.most_common()[-1][0]
    if counter.most_common()[0][1] == counter.most_common()[-1][1]:
        least_common_bit = '0'
Exemplo n.º 3
0
from aoc import get_input_as, submit
from collections import defaultdict

inp = get_input_as()

SEGMENTS = {
    0: 'abcefg',
    1: 'cf',
    2: 'acdeg',
    3: 'acdfg',
    4: 'bcdf',
    5: 'abdfg',
    6: 'abdefg',
    7: 'acf',
    8: 'abcdefg',
    9: 'abcdfg'
}

F_SEGMENTS = {
    hash(''.join(sorted('abcefg'))): 0,
    hash(''.join(sorted('cf'))): 1,
    hash(''.join(sorted('acdeg'))): 2,
    hash(''.join(sorted('acdfg'))): 3,
    hash(''.join(sorted('bcdf'))): 4,
    hash(''.join(sorted('abdfg'))): 5,
    hash(''.join(sorted('abdefg'))): 6,
    hash(''.join(sorted('acf'))): 7,
    hash(''.join(sorted('abcdefg'))): 8,
    hash(''.join(sorted('abcdfg'))): 9,
}
ans = 0
Exemplo n.º 4
0
        for c in range(len(self.rows)):
            col = []
            for r in self.rows:
                col.append(r[c])
            if all(c[1] for c in col):
                return True
        return False

    def get_score(self, num):
        unmarked_sum = 0
        for r in self.rows:
            for c, checked in r:
                if not checked:
                    unmarked_sum += c
        return unmarked_sum * num


inp = get_input_as(str, sep='\n\n')

draw = map(int, inp.pop(0).split(','))
boards = []
for i in inp:
    boards.append(Board(i))

for num in draw:
    for board in boards:
        board.play_num(num)
        if board.check_win():
            print(board.get_score(num))
            exit(0)
Exemplo n.º 5
0
# with open('input.txt') as f:
#     inp = list(map(int, f.read().splitlines()))

# count = 0

# for n, val in enumerate(inp):
#     if val > inp[n - 1]:
#         count += 1

# print(count)

import aoc

print(aoc.get_input_as(int))