Compare commits
4 commits
1df896c32c
...
ae8759d766
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | ae8759d766 | ||
Bruno BELANYI | 2462651cae | ||
Bruno BELANYI | 0e75993cb4 | ||
Bruno BELANYI | f6f597a892 |
25
2024/d01/ex1/ex1.py
Executable file
25
2024/d01/ex1/ex1.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(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
Normal file
1000
2024/d01/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
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()
|
1000
2024/d01/ex2/input
Normal file
1000
2024/d01/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue