Skip to content

Commit

Permalink
2022 day 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacerulerwill committed Jan 8, 2025
1 parent f6baeb5 commit 99689c1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions puzzles/Y2015/D5/p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def puzzle(input: str) -> Any:
for line in lines:
first = False
for i in range(len(line) - 3):
sub = line[i:i + 2]
if sub in line[i + 2:]:
sub = line[i : i + 2]
if sub in line[i + 2 :]:
first = True
break
if not first:
Expand Down
11 changes: 11 additions & 0 deletions puzzles/Y2022/D1/p1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from typing import Any


def puzzle(input: str) -> Any:
groupedCalories = input.strip().split("\n\n")
highest = 0
for group in groupedCalories:
total = sum(int(calorie) for calorie in group.split("\n"))
if total > highest:
highest = total
return highest
13 changes: 13 additions & 0 deletions puzzles/Y2022/D1/p2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import heapq
from typing import Any


def puzzle(input: str) -> Any:
groupedCalories = input.strip().split("\n\n")
elvesCalories = []
for group in groupedCalories:
elvesCalories.append(sum(int(calorie) for calorie in group.split("\n")))
# convert to negative to get 3 smallest using min heap
elvesCalories = [-calories for calories in elvesCalories]
heapq.heapify(elvesCalories)
return sum(heapq.heappop(elvesCalories) * -1 for _ in range(3))
Empty file added puzzles/Y2022/__init__.py
Empty file.

0 comments on commit 99689c1

Please sign in to comment.