Skip to content

Commit

Permalink
Use zip()
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed Dec 1, 2024
1 parent 020404c commit f9772ae
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions aoc2024/src/day01/python/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from collections import defaultdict
from typing import Sequence

type LocationIds = Sequence[int]
type _LocationIds = Sequence[int]

def _parse_input(input: Sequence[str]) -> tuple[LocationIds, LocationIds]:
"""Converts puzzle input into 2 lists of location IDs.
def _parse_input(input: Sequence[str]) -> tuple[_LocationIds, _LocationIds]:
"""Converts puzzle input into 2 sequences of location IDs.
n = len(input)
Time complexity: O(n)
Expand Down Expand Up @@ -52,8 +52,8 @@ def calculate_distance(input: Sequence[str]) -> int:
location_ids1.sort() # t:O(nlogn)
location_ids2.sort() # t:O(nlogn)
return sum(
abs(location_ids1[i] - location_ids2[i])
for i in range(0, len(location_ids1))) # t:O(n)
abs(id1 - id2)
for id1, id2 in zip(location_ids1, location_ids2)) # t:O(n)

def calculate_similarity_score(input: Sequence[str]) -> int:
"""
Expand Down

0 comments on commit f9772ae

Please sign in to comment.