-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpart_one.py
49 lines (34 loc) · 1.11 KB
/
part_one.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from sys import maxsize
from typing import override
from infrastructure.solutions.base import Solution
class Year2017Day2Part1Solution(Solution):
@classmethod
@override
def parse_input(cls, text_input: str) -> dict[str, list[list[int]]]:
spreadsheet = []
for row in text_input.split('\n'):
if not row:
continue
row = [int(num) for num in row.split()]
spreadsheet.append(row)
return {'spreadsheet': spreadsheet}
@classmethod
@override
def solve(cls, spreadsheet: list[list[int]]) -> int:
"""
Time: O(n*m)
Space: O(1)
Where n - number of rows in spreadsheet
m - maximum spreadsheet row length
"""
checksum = 0
for row in spreadsheet:
minimum = maxsize
maximum = -maxsize
for num in row:
minimum = min(minimum, num)
maximum = max(maximum, num)
checksum += maximum - minimum
return checksum
if __name__ == '__main__':
print(Year2017Day2Part1Solution.main())