2024: d01: ex2: add solution
This commit is contained in:
parent
2f2e26f5fc
commit
2c356cfd6f
25
2024/d01/ex2/ex2.py
Executable file
25
2024/d01/ex2/ex2.py
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: list[str]) -> int:
|
||||
def parse(input: list[str]) -> tuple[list[int], list[int]]:
|
||||
left, right = [], []
|
||||
for line in input:
|
||||
lhs, rhs = line.split()
|
||||
left.append(int(lhs))
|
||||
right.append(int(rhs))
|
||||
return left, right
|
||||
|
||||
left, right = parse(input)
|
||||
return sum(lhs * right.count(lhs) for lhs in left)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue