sub_packet, packet = packet[:length_bits], packet[length_bits:] while sub_packet: val, sub_packet = parse(sub_packet) values.append(val) elif length_id == "1": num_subs, packet = int(packet[:11], 2), packet[11:] for _ in range(0, num_subs): val, packet = parse(packet) values.append(val) value = TYPES[type_id](values) return value, packet @utils.time_func def part1() -> int: _ = parse(get_bin_data()) return sum(VERSION_NUMBERS) @utils.time_func def part2() -> int: # 562406347874 too low return parse(get_bin_data())[0] utils.print_result(f"Part 1 answer: {part1()}") utils.print_result(f"Part 2 answer: {part2()}")
start: int, check: int ) -> Union[list[int], bool]: # noqa pylint: disable=unsubscriptable-object total = 0 for i in range(start, len(inputdata)): total += inputdata[i] if total == check: return inputdata[start : (i + 1)] elif total > check: return False return False def part1() -> int: return get_invalid() def part2(found: int) -> int: for i in range(0, len(inputdata)): is_contiguous: Union[list[int], bool] = find_contiguous( i, found ) # noqa pylint: disable=unsubscriptable-object if isinstance(is_contiguous, list): return min(is_contiguous) + max(is_contiguous) return 0 p1: int = part1() utils.print_result(f"Part 1 answer: {p1}") utils.print_result(f"Part 2 answer: {part2(p1)}")
0, len(input_list) - d_y, len(input_list[0]), ) while cur_y < length: cur_x = (cur_x + d_x) % width cur_y += d_y if input_list[cur_y][cur_x] == TREE: trees += 1 return trees def part1(): return get_trees_in_slope(3, 1) def part2(part1_trees: int) -> int: moves: list[list[int]] = [[1, 1], [5, 1], [7, 1], [1, 2]] trees: int = part1_trees for move in moves: trees *= get_trees_in_slope(move[0], move[1]) return trees PART1_TREES = part1() utils.print_result(f"Part 1 answer: {PART1_TREES}") utils.print_result(f"Part 2 answer: {part2(PART1_TREES)}")