2021: d07: ex1: add solution
This commit is contained in:
parent
2c8baf5722
commit
127c13e162
21
2021/d07/ex1/ex1.py
Executable file
21
2021/d07/ex1/ex1.py
Executable file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def solve(input: List[str]) -> int:
|
||||
nums = sorted(int(n) for n in input[0].split(","))
|
||||
median = nums[len(nums) // 2]
|
||||
|
||||
return sum(abs(n - median) for n in nums)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [line.strip() for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue