2017: d02: ex1: add solution
This commit is contained in:
parent
fa3a1ae980
commit
b252c19691
1 changed files with 23 additions and 0 deletions
23
2017/d02/ex1/ex1.py
Executable file
23
2017/d02/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: str) -> int:
|
||||
def parse(input: str) -> list[list[int]]:
|
||||
return [[int(n) for n in line.split()] for line in input.splitlines()]
|
||||
|
||||
def checksum(row: list[int]) -> int:
|
||||
return max(row) - min(row)
|
||||
|
||||
sheet = parse(input)
|
||||
return sum(map(checksum, sheet))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue