Compare commits
No commits in common. "ae8759d766439c7186fbe6d0c73d8a9c793ed1e7" and "1df896c32ca8a62739cfcdb648744c1a405d744b" have entirely different histories.
ae8759d766
...
1df896c32c
|
@ -1,25 +0,0 @@
|
||||||
#!/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(abs(lhs - rhs) for lhs, rhs in zip(sorted(left), sorted(right)))
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
input = sys.stdin.read().splitlines()
|
|
||||||
print(solve(input))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
1000
2024/d01/ex1/input
1000
2024/d01/ex1/input
File diff suppressed because it is too large
Load diff
|
@ -1,25 +0,0 @@
|
||||||
#!/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()
|
|
1000
2024/d01/ex2/input
1000
2024/d01/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue