Initial Commit
This commit is contained in:
parent
298c5ef9d1
commit
7a0e3ab9ab
2 changed files with 1047 additions and 0 deletions
1000
Day1/input
Normal file
1000
Day1/input
Normal file
File diff suppressed because it is too large
Load diff
47
Day1/solution.py
Normal file
47
Day1/solution.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
from typing import List
|
||||
|
||||
class Solution:
|
||||
def __init__(self) -> None:
|
||||
self.lines: List[str] = []
|
||||
self.left_array: List[int] = []
|
||||
self.right_array: List[int] = []
|
||||
self.result: int = 0
|
||||
|
||||
def read(self) -> None:
|
||||
with open("input") as f:
|
||||
self.lines = f.readlines()
|
||||
|
||||
def clean(self) -> None:
|
||||
for i in range(len(self.lines)):
|
||||
self.lines[i] = self.lines[i].strip()
|
||||
|
||||
def split_lines(self) -> None:
|
||||
for line in self.lines:
|
||||
elements: List[str] = line.split()
|
||||
clean_element: int = int(elements[0])
|
||||
self.left_array.append(clean_element)
|
||||
clean_element: int = int(elements[1])
|
||||
self.right_array.append(clean_element)
|
||||
|
||||
def sort_lists(self) -> None:
|
||||
self.left_array.sort()
|
||||
self.right_array.sort()
|
||||
|
||||
def calculate_difference(self) -> None:
|
||||
for i in range(len(self.left_array)):
|
||||
difference: int = abs(self.right_array[i] - self.left_array[i])
|
||||
self.result += difference
|
||||
|
||||
|
||||
def main() -> None:
|
||||
solver: Solution = Solution()
|
||||
solver.read()
|
||||
solver.clean()
|
||||
solver.split_lines()
|
||||
solver.sort_lists()
|
||||
solver.calculate_difference()
|
||||
print(solver.result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue