day 1 - part 1
This commit is contained in:
parent
bbd0702bf7
commit
4bdbcdbb56
4 changed files with 48 additions and 5 deletions
|
@ -1,5 +1,29 @@
|
|||
def main():
|
||||
pass
|
||||
from pathlib import Path
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
def get_ordered_lists(data_file: Path) -> tuple[list[int], list[int]]:
|
||||
list1 = list()
|
||||
list2 = list()
|
||||
for line in data_file.open():
|
||||
numbers = line.strip().split(" ")
|
||||
list1.append(int(numbers[0]))
|
||||
list2.append(int(numbers[1]))
|
||||
return sorted(list1), sorted(list2)
|
||||
|
||||
|
||||
def compute_distance(list1, list2) -> int:
|
||||
return sum([abs(item2 - item1) for item1, item2 in zip(list1, list2)])
|
||||
|
||||
|
||||
def compute(data_file: Path) -> int:
|
||||
list1, list2 = get_ordered_lists(data_file)
|
||||
return compute_distance(list1, list2)
|
||||
|
||||
|
||||
def main():
|
||||
file = Path(__file__).parent / "first-input"
|
||||
print(compute(file))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue