aboutsummaryrefslogtreecommitdiff
path: root/2024/25/puzzle-1.py
blob: 2ad6581eb43ad4bd3ae3bf6f4a02a0e5289f465c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3

import itertools


def main() -> None:
	keys: list[int] = []
	locks: list[int] = []

	with open("input", "r") as f:
		schems = f.read().split("\n\n")

	for schem in schems:
		n = 0
		for char in schem:
			if char == '\n':
				continue
			n <<= 1
			if char == '#':
				n |= 1
		(locks if n >= 0x7C0000000 else keys).append(n)

	def nand(x: int, y: int) -> bool:
		return not x & y

	print(sum(itertools.starmap(nand, itertools.product(keys, locks))))


if __name__ == "__main__":
	main()