This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I went for speed on this one, it was a mess | |
HEIGHT = len(INPUT.split("\n")) | |
WIDTH = len(INPUT.split("\n")[0]) | |
grid = dict() | |
for y, line in enumerate(INPUT.split("\n")): | |
for x, c in enumerate(line): | |
grid[(x, y)] = c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
adapters = [int(x) for x in INPUT.split("\n")] | |
# Part 1 | |
last = 0 | |
differences = [] | |
for n in sorted(adapters): | |
differences.append(n - last) | |
last = n | |
differences.append(3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import operator | |
from itertools import accumulate, combinations, product | |
INPUT="""...""" | |
PREAMBLE = 25 | |
values = [int(n) for n in INPUT.split("\n")] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_program(program): | |
acc = 0 | |
pointer = 0 | |
seen = set() | |
while pointer not in seen: | |
op, value = program[pointer] | |
seen.add(pointer) | |
if op == 'nop': | |
pointer += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
print("Part 1") | |
print(sum([len(set(list(bunch.replace("\n", "")))) for bunch in INPUT.split("\n\n")])) | |
print("Part 2") | |
print(sum(len(reduce(set.intersection, [set(line) for line in bunch.split("\n")])) for bunch in INPUT.split("\n\n"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def partition(start, end, top): | |
if top: | |
return start, start + (end - start) // 2 | |
return start + (end - start) // 2 + 1, end | |
def score_seat(boarding_pass): | |
start_row = 0 | |
end_row = 127 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
REQUIRED_KEYS = [ | |
'byr', | |
'iyr', | |
'eyr', | |
'hgt', | |
'hcl', | |
'ecl', | |
'pid' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WIDTH = len(INPUT.split("\n")[0]) | |
# Part 1 | |
trees = 0 | |
for i, line in enumerate(INPUT.split("\n")): | |
if line[i * 3 % WIDTH] == '#': | |
trees += 1 | |
print(trees) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
valid = 0 | |
# Part 1 | |
for line in INPUT.split("\n"): | |
m = re.match(r"(\d+)-(\d+) (\S): (\S+)", line) | |
(low, high, character, password) = m.groups() | |
if int(low) <= password.count(character) <= int(high): | |
valid += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import math | |
numbers = [int(x) for x in INPUT.split("\n")] | |
# Part 1 | |
print([math.prod(match) for match in itertools.combinations(numbers, 2) if sum(match) == 2020]) | |
# Part 2 | |
print([math.prod(match) for match in itertools.combinations(numbers, 3) if sum(match) == 2020]) |
NewerOlder