"""Run the script.""" import collections import pathlib from utils import inputs from . import string_processing INPUT_PATH = inputs.input_path(2, "passwords") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # get input rows = [x.strip() for x in INPUT_PATH.read_text().splitlines()] sleigh_count = collections.Counter( string_processing.is_row_valid_sleigh(row) for row in rows) toboggan_count = collections.Counter( string_processing.is_row_valid_toboggan(row) for row in rows) print( "🛷 Sleigh Policy", f"Number of valid rows: {sleigh_count[True]}", f"Number of invalid rows: {sleigh_count[False]}", "🧝 Toboggan Policy", f"Number of valid rows: {toboggan_count[True]}", f"Number of invalid rows: {toboggan_count[False]}", sep="\n", )
"""Run the script.""" import math import pathlib from utils import inputs from . import expenses INPUT_PATH = inputs.input_path(1, "expenses") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # get input inputs = [int(x) for x in INPUT_PATH.read_text().splitlines()] for n in [2, 3]: # find expenses answer = expenses.find_inputs_which_sum_to(inputs, target := 2020, n) # multiply together final_product = math.prod(answer) # tell the user answers = ", ".join(f"{a:,d}" for a in answer) print( ( f"The {n} expenses which sum to {target:,d} are {answers}, " f"their product is {final_product:,d}" ) )
"""Run the script.""" import math import pathlib from utils import inputs from . import _types as task_types from . import navigate INPUT_PATH = inputs.input_path(3, "map") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # inputs encounters = [] for dx, dy in [(3, 1), (1, 1), (5, 1), (7, 1), (1, 2)]: # get map text = INPUT_PATH.read_text().strip() array = navigate.parse_string_to_array(text.splitlines()) len_down = len(array) gradient = dx / dy my_map = navigate.build_map_of_min_width( text, math.ceil(len_down * gradient)) encountered_trees = navigate.traverse_slope_count_val( my_map, dx, dy, task_types.Item.TREE) encounters.append(encountered_trees) forest = task_types.Item.TREE.value * encountered_trees print(f"Slope: {dx}, {dy}: encountered {encountered_trees} on " f"the way down: {forest}")
"""Run the script.""" import collections import math import pathlib from utils import inputs from . import seating INPUT_PATH = inputs.input_path(5, "seating") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # inputs inputs = INPUT_PATH.read_text().strip() seats = [seating.parse_boarding_pass(seat) for seat in inputs.splitlines()] seat_ids = [seating.get_seat_id(seat) for seat in seats] max_seat_id = max(seat_ids) print(f"Max seat ID: {max_seat_id}") missing_seat_id = seating.find_missing_seat(seat_ids) print(f"Missing seat ID: {missing_seat_id}")
"""Run the script.""" import collections import math import pathlib from utils import inputs from . import declarations INPUT_PATH = inputs.input_path(6, "declarations") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # inputs inputs = INPUT_PATH.read_text().strip() declarations_anyone = declarations.parse_declarations_anyone(inputs) declarations_everyone = declarations.parse_declarations_everyone(inputs) total_questions_anyone = sum(len(d) for d in declarations_anyone) total_questions_everyone = sum(len(d) for d in declarations_everyone) print(f"Total answered (anyone): {total_questions_anyone}") print(f"Total answered (everyone): {total_questions_everyone}")
"""Run the script.""" import collections import math import pathlib from utils import inputs from . import passport INPUT_PATH = inputs.input_path(4, "passports") assert INPUT_PATH.exists(), INPUT_PATH if __name__ == "__main__": # inputs inputs = INPUT_PATH.read_text().strip() passports = passport.parse_input(inputs) num_valid = collections.Counter( passport.is_passport_valid(p) for p in passports ) print(f"Total valid: {num_valid[True]}")