Skip to content

Commit

Permalink
Tidy CodingQuest d28
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacG committed Mar 4, 2024
1 parent 5f1dc93 commit 746c30d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions codingquest/2024/solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@

def purchase_tickets(data: str) -> int:
"""Day 28: Return the cheapest airline cost."""
pattern = re.compile(r"(\S+): (\S+) (\d+)")
negative = ("Rebate", "Discount")
costs = collections.defaultdict(int)
for line in data.splitlines():
airline, item = line.split(": ")
item_type, cost = item.split()
cost = int(cost)
if item_type in ("Rebate", "Discount"):
cost *= -1
costs[airline] += cost
airline, item_type, cost = pattern.fullmatch(line).groups()
costs[airline] += int(cost) * (-1 if item_type in negative else 1)
return min(costs.values())


Expand Down

0 comments on commit 746c30d

Please sign in to comment.