import matrix import shared from collections import Counter # XMAS = ['X','M','A','S'] XMAS = "XMAS" # @shared.profile def part1(mx): count = 0 for idr, row in enumerate(mx): for idc, c in enumerate(row): los = matrix.line_of_sight(mx, idr, idc, distance=4, diagonals=True) words = list(map("".join, los.values())) counter = Counter(words) count += counter[XMAS] print(count) # @shared.profile def part2(rows): pass def main(): mx = matrix.load_matrix_file(shared.get_fname(4), str) with shared.elapsed_timer() as elapsed: part1(mx) print("🕒", elapsed()) rows = [row for row in shared.load_rows(4, True)] with shared.elapsed_timer() as elapsed: part2(rows) print("🕒", elapsed()) if __name__ == "__main__": main()