day 1 - part 2
This commit is contained in:
parent
b844fafd78
commit
5f492b3f66
6 changed files with 99 additions and 22 deletions
|
@ -1,25 +1,19 @@
|
|||
from pathlib import Path
|
||||
|
||||
|
||||
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)
|
||||
from day1.common import get_ordered_lists
|
||||
|
||||
|
||||
def compute_distance(list1, list2) -> int:
|
||||
return sum([abs(item2 - item1) for item1, item2 in zip(list1, list2)])
|
||||
|
||||
|
||||
def main():
|
||||
file = Path(__file__).parent / "input-data"
|
||||
list1, list2 = get_ordered_lists(file)
|
||||
print(compute_distance(list1, list2))
|
||||
def main(data_file: Path):
|
||||
list1, list2 = get_ordered_lists(data_file)
|
||||
distance = compute_distance(list1, list2)
|
||||
print(distance)
|
||||
return distance
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
file = Path(__file__).parent / "input-data"
|
||||
main(file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue