def main(): input = get_input(day=17) start = time.time() print("first:", one(input)) print('It took', time.time() - start, 'seconds for first.') start = time.time() print("second:", two(input)) print('It took', time.time() - start, 'seconds for second.')
def main(): input = get_input(day=16) ix_my_ticket = input.index('your ticket:') my_ticket = input[ix_my_ticket + 1] nearby = input[input.index('nearby tickets:') + 1:] start = time.time() print("first:", one(input[:ix_my_ticket - 1], nearby)) print('It took', time.time() - start, 'seconds for first.') start = time.time() print("second:", two(input[:ix_my_ticket - 1], nearby, my_ticket)) print('It took', time.time() - start, 'seconds for second.')
def main(): input = get_input(day=10) input = list(map(int, input)) print("first:", one(input[:])) print("second:", two(input[:]))
def main(): input = get_input(day=7) print("first:", one(input)) print("second:", two(input))
from aoc_utils import get_input data = get_input( year=2020, day=3, lines=True ) def part1(slope): x_off, y_off = slope x, y = 0, 0 trees_count = 0 while y < len(data): if data[y][x % len(data[0])] == '#': trees_count += 1 x += x_off y += y_off return trees_count def part2(): slopes = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] result = 1 for slope in slopes: result *= part1(slope)
import re from aoc_utils import get_input data = get_input(year=2020, day=4) passwords = [ dict(re.findall(r"([a-z]{3}):([^\s]+)", x.replace("\n", " "))) for x in data.split("\n\n") ] def part1(): valid_count = 0 for password in passwords: valid_count += int({'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid'} <= password.keys()) return valid_count def part2(): def check_number(value, min, max): return value.isdigit() and min <= int(value) <= max valid_count = 0 for password in passwords: if not {'byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid' } <= password.keys(): continue if 'byr' in password and not check_number(password['byr'], 1920, 2002):
def main(): input = list(map(int, get_input(day=1))) print("first:", one(input)) print("second:", two(input)) print(sorted(input))
from collections import defaultdict from aoc_utils import get_input, perf data = get_input(year=2020, day=10, lines=True, numbers=True) data = sorted(data) def part1(): diffs = defaultdict(int) diffs[3] += 1 for i in range(len(data)): if i == 0: diffs[data[i]] += 1 else: diffs[data[i] - data[i - 1]] += 1 return diffs[1] * diffs[3] def part2(): last, ones = 0, 0 value = 1 for i, num in enumerate(data): if num - last == 1: ones += 1 if num - last == 3 or i == len(data) - 1: if ones == 2: value *= 2 elif ones == 3: value *= 4
def main(): input = list(map(int, get_input(day=9))) preamble = 25 print("first:", one(input, preamble)) print("second:", two(input, preamble))
from time import perf_counter from aoc_utils import get_input from z3 import * data = get_input(2020, 1, lines=True, numbers=True) def part1(): s = Solver() x, y, result = Ints("x y result") s.add(Or(*[x == val for val in data])) s.add(Or(*[y == val for val in data])) s.add(x != y) s.add(x + y == 2020) s.add(x * y == result) s.check() return s.model()[result] def part2(): s = Solver() x, y, z, result = Ints("x y z result") s.add(Or(*[x == val for val in data])) s.add(Or(*[y == val for val in data])) s.add(Or(*[z == val for val in data])) s.add((x != y) != z) s.add(x + y + z == 2020)