def test_part1(self): lines = get_input_file_lines_no_nl('day21.txt') ingredients_list, allergens_list = parse_input(lines) alg_to_ing = allergens_to_possible_ingredient( ingredients_list, allergens_list) result = part01(ingredients_list, allergens_list, alg_to_ing) self.assertEqual(result, 2485)
def test_part2(self): lines = get_input_file_lines_no_nl('day21.txt') ingredients_list, allergens_list = parse_input(lines) alg_to_ing = allergens_to_possible_ingredient( ingredients_list, allergens_list) result = part02(alg_to_ing) self.assertEqual( result, 'bqkndvb,zmb,bmrmhm,snhrpv,vflms,bqtvr,qzkjrtl,rkkrx')
return current_active_cubes def part01_v3(lines): active_cubes = parse_active_points(lines, 3) active_cubes_end = simulate_cubes_v3(active_cubes, 6) print('Part 1:', len(active_cubes_end)) def part02_v3(lines): active_cubes = parse_active_points(lines, 4) active_cubes_end = simulate_cubes_v3(active_cubes, 6) print('Part 2:', len(active_cubes_end)) def parse_active_points(lines, dimensions=3): active_set = set() for y, line in enumerate(lines): for x, c in enumerate(line): if c == ACTIVE: coords = [x, y] + [0] * (dimensions - 2) point = Point(coords) active_set.add(point) return active_set if __name__ == '__main__': lines = get_input_file_lines_no_nl('day17.txt') part01_v3(lines) part02_v3(lines)
surrounding = {} for i in range(1, nrow - 1): for j in range(1, ncol - 1): surrounding[(i, j)] = count_method(i, j, seats) for i in range(1, nrow - 1): for j in range(1, ncol - 1): if seats[(i, j)] == 'L' and surrounding[(i, j)] == 0: seats[(i, j)] = '#' change = True elif seats[(i, j)] == '#' and surrounding[(i, j)] >= vis_limit: seats[(i, j)] = 'L' change = True return ''.join(seats.values()).count('#') def part01(seats, nrow, ncol): print(f'part01: {count_seats_after_reseating(seats, nrow, ncol, 4)}') def part02(seats, nrow, ncol): print( f'part02: {count_seats_after_reseating(seats, nrow, ncol, 5, count_first_visible)}' ) if __name__ == '__main__': lines = get_input_file_lines_no_nl('day11_seats.txt') res = convertToSeats(lines) part01(*res) part02(*res)
def test01(self): lines = get_input_file_lines_no_nl( '../inputs/day19_test.txt') assert part01(lines) == 2
def test04_shortened(self): lines = get_input_file_lines_no_nl( '../inputs/day19_test04_short.txt') assert part02(lines) == 1
def count_num_removable(jolts, start): count = -1 while jolts[start] + 3 >= jolts[ start + 2 + count] and start + 2 + count < len(jolts) - 1: count += 1 count = sum([ 1 for i in range(start + 1, start + 3) if i < len(jolts) - 1 and abs(jolts[start] - jolts[i + 1]) <= 3 ]) return max(0, count) starting_point = [0] + sorted(jolts) + [max(jolts) + 3] removable = {} for i in range(0, len(starting_point) - 1): removable[i] = count_num_removable(starting_point, i) print(removable) options_accum = {len(starting_point) - 2: 1, len(starting_point) - 1: 1} for index in range(len(starting_point) - 3, -1, -1): options_accum[index] = sum([ options_accum[index + 1 + i] for i in range(removable[index] + 1) ]) print(f'part 02: {options_accum[0]}') if __name__ == '__main__': lines = get_input_file_lines_no_nl('day10_adapters.txt') jolts = [int(x) for x in lines] # part01_trick(jolts) part02(jolts)