50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
import sys
|
|
import typing
|
|
|
|
|
|
def main() -> int:
|
|
inputs = [int(s) for s in sys.stdin.read().split()]
|
|
for i, j in _find_2020_pairs(inputs):
|
|
print(f"pair: {i} * {j} == {i * j}")
|
|
|
|
for i, j, k in _find_2020_triplets(inputs):
|
|
print(f"triplet: {i} * {j} * {k} == {i * j * k}")
|
|
return 0
|
|
|
|
|
|
def _find_2020_pairs(
|
|
inputs: typing.List[int],
|
|
) -> typing.Generator[typing.Tuple[int, ...], None, None]:
|
|
found = []
|
|
|
|
for i, in0 in enumerate(inputs):
|
|
for j, in1 in enumerate(inputs):
|
|
if i == j:
|
|
continue
|
|
if in0 + in1 == 2020:
|
|
to_yield = tuple(sorted([in0, in1]))
|
|
if to_yield not in found:
|
|
yield to_yield
|
|
found.append(to_yield)
|
|
|
|
|
|
def _find_2020_triplets(
|
|
inputs: typing.List[int],
|
|
) -> typing.Generator[typing.Tuple[int, ...], None, None]:
|
|
found = []
|
|
|
|
for i, in0 in enumerate(inputs):
|
|
for j, in1 in enumerate(inputs):
|
|
for k, in2 in enumerate(inputs):
|
|
if i == j or i == k:
|
|
continue
|
|
if in0 + in1 + in2 == 2020:
|
|
to_yield = tuple(sorted([in0, in1, in2]))
|
|
if to_yield not in found:
|
|
yield to_yield
|
|
found.append(to_yield)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|