to_delete.append(i) boards = np.delete(boards, to_delete, 0) if __name__ == '__main__': puzzle_input = """7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 22 13 17 11 0 8 2 23 4 24 21 9 14 16 7 6 10 3 18 5 1 12 20 15 19 3 15 0 2 22 9 18 13 17 5 19 8 7 25 23 20 11 10 24 4 14 21 16 12 6 14 21 17 24 4 10 16 15 9 19 18 8 23 26 20 22 11 13 6 5 2 0 12 3 7 """.splitlines() puzzle_input = get_input(4).splitlines() start = perf_counter() part12(puzzle_input) print(f"Total runtime: {perf_counter()-start}")
def part2(hm): hm = np.where(hm != 9, True, hm) hm = np.where(hm == 9, False, hm) lens = [] while np.nonzero(hm)[0].any(): lens.append(bas_size(hm, np.nonzero(hm)[1][0], np.nonzero(hm)[0][0], 0)) return np.prod(sorted(lens)[-3:]) if __name__ == '__main__': puzzle_input = " ".join("""2199943210 3987894921 9856789892 8767896789 9899965678""").splitlines() puzzle_input = " ".join(get_input(9)).splitlines() hm = np.loadtxt(puzzle_input, int) hm = np.c_[np.ones(len(hm), int) * 9, hm, np.ones(len(hm), int) * 9] hm = np.vstack( [np.ones(len(hm[0]), int) * 9, hm, np.ones(len(hm[0]), int) * 9]) start = perf_counter() print(f"Part 1: {part1(hm)}, time: {perf_counter()-start}") start2 = perf_counter() print(f"Part 2: {part2(hm)}, time: {perf_counter() - start2}") print(f"Total runtime: {perf_counter() - start}")