x = parsed_claim.x y = parsed_claim.y for i in range(0, parsed_claim.width): for j in range(0, parsed_claim.length): if fabric[x][y] == 0: fabric[x][y] = parsed_claim.id else: overlapping_claim_ids.add(parsed_claim.id) overlapping_claim_ids.add(fabric[x][y]) fabric[x][y] = "X" y += 1 x += 1 y = parsed_claim.y counter = 0 for i in range(0, 1000): for j in range(0, 1000): if fabric[i][j] == "X": counter += 1 print("Square inches of fabric withing two or more claims: " + str(counter)) print("The one claim that doesn't overlap: " + str(claim_ids - overlapping_claim_ids)) input_data = util.read_input_from_file("input-files/day-3.txt") resolve_both_puzzles(input_data)
counter += 1 if counter > largest_area: largest_area = counter print("Largest area: " + str(largest_area)) def resolve_second_puzzle(points_list, max_x, max_y): safe_region_size = 0 for x in range(0, max_x): for y in range(0, max_y): total_dist = 0 for point in points_list: total_dist += calculate_dist(point, Point(x, y)) if total_dist < 10000: safe_region_size += 1 print("Safe region size: " + str(safe_region_size)) raw_input = util.read_input_from_file("input-files/day-6.txt") parsed_list = parse_points_list(raw_input) (max_x, max_y) = find_max_coordinates(parsed_list) board = create_board_for_first_puzzle(parsed_list, max_x, max_y) resolve_first_puzzle(board, parsed_list, max_x, max_y) resolve_second_puzzle(parsed_list, max_x, max_y)
return nanobots, nanobot_with_highest_range def calculate_distance(first_nanobot, second_nanobot): return abs(first_nanobot.x - second_nanobot.x) + abs(first_nanobot.y - second_nanobot.y) \ + abs(first_nanobot.z - second_nanobot.z) def create_nanobots_in_range_list(nanobots, nanobot_with_highest_range): nanobots_in_range = [] for nanobot in nanobots: distance = calculate_distance(nanobot, nanobot_with_highest_range) if distance <= nanobot_with_highest_range.range: nanobots_in_range.append(nanobot) return nanobots_in_range def get_coordinates_in_range_of_most_nanobots(nanobots): pass file_input = util.read_input_from_file("input-files/day-23.txt") nanobots_list, strongest_nanobot = create_nanobots_list(file_input) nanobots_in_range_of_strongest = create_nanobots_in_range_list( nanobots_list, strongest_nanobot) print("There's " + str(len(nanobots_in_range_of_strongest)) + " nanobots in signal radius of the strongest nanobot.")
else: map[x][y] = "-" map[x+1][y] = ">" elif map[x][y] == "<": pass elif map[x][y] == "v": pass elif map[x][y] == "^": pass return map def print_map(map): for row in map: for char in row: print(char, end=" ") map = util.read_input_from_file("input-files/day-13.txt") print_map(map) for i in range(5): move_carts(map) print_map(map)
import util import re import importlib day_16 = importlib.import_module("day-16") def perform_instruction(method, values, registers, const_ip, ip): registers[const_ip] = ip method_to_call = getattr(day_16, method) registers = method_to_call(registers, values) return registers, registers[const_ip] + 1 instructions = util.read_input_from_file("input-files/day-19.txt") const_ip = int(instructions[0][4]) ip = 0 registers = [1, 0, 0, 0, 0, 0] while ip < len(instructions) - 1: current_instruction = instructions[ip + 1] pattern = re.compile(r"^(?P<method>.*?)\s(?P<value1>.*?)\s(?P<value2>.*?)\s(?P<value3>.*?)\n") match = pattern.match(current_instruction) method = match.group("method") values = [0, 0, 0, 0] for i in range(1, 4): values[i] = int(match.group("value" + str(i)))