Skip to content

Commit

Permalink
going to Toulouse, day1 in the middle
Browse files Browse the repository at this point in the history
  • Loading branch information
reycardo committed Dec 1, 2023
1 parent 5bfb611 commit 8418e0a
Show file tree
Hide file tree
Showing 5 changed files with 1,040 additions and 2,295 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/badges.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ jobs:
starsRegex: '(?<=https:\/\/img\.shields\.io\/badge\/2022_stars%20⭐-)[0-9]+(?=-yellow)' # Regular expression that finds the content of the stars badge in your file.
daysCompletedRegex: '(?<=https:\/\/img\.shields\.io\/badge\/2022_days%20completed-)[0-9]+(?=-red)' # Regular expression that finds the content of the days completed badge iun your file.

- uses: joblo2213/aoc-badges-action@v3
with:
userid: 1439540 # your user id, see setup on how to obtain
session: ${{ secrets.AOC_SESSION }} # secret containing session code, see setup on how to obtain
year: 2023 # The year for which stats should be retrieved
leaderboard: 'https://adventofcode.com/2023/leaderboard/private/view/1439540.json' # The url of the leaderboard from witch the data is fetched. Typically your private leaderboard.
file: 'README.md' # The file that contains the badges
starsRegex: '(?<=https:\/\/img\.shields\.io\/badge\/2023_stars%20⭐-)[0-9]+(?=-yellow)' # Regular expression that finds the content of the stars badge in your file.
daysCompletedRegex: '(?<=https:\/\/img\.shields\.io\/badge\/2023_days%20completed-)[0-9]+(?=-red)' # Regular expression that finds the content of the days completed badge iun your file.


- uses: stefanzweifel/git-auto-commit-action@v4 # Step that pushes these local changes back to your github repo
with:
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
![](https://img.shields.io/badge/2022_stars%20⭐-26-yellow)
![](https://img.shields.io/badge/2022_days%20completed-13-red)

![](https://img.shields.io/badge/2023_stars%20⭐-26-yellow)
![](https://img.shields.io/badge/2023_days%20completed-13-red)

## Quick start (Windows)

### Pyenv-win
Expand Down
54 changes: 23 additions & 31 deletions advent-of-code/src/2023/Day1/day1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,53 @@
#########


class ElfCalories:
class Calibration:
def __init__(self, text_input: list):
self.input = text_input
self.elf_calorie_dict = self.get_elf_dict()
self.elf_count = len(self.elf_calorie_dict)

def get_elf_dict(self):
d = {
elf: list(sub[1])
for elf, sub in enumerate(groupby(self.input, key=bool))
if sub[0]
} # groups into an enumerated dict if key is not ''
return {
k: (v, sum(v)) for k, v in d.items()
} # returns dict where key is elf number, v is list of elf calories, sum(v) is total cals elf has

def get_max(self, number):
# sorts descending, gets top number
return sum(
n
for _, n in sorted(
self.elf_calorie_dict.values(), key=lambda t: t[1], reverse=True
)[:number]
)

def get_calib_values(self, input_string: str):
# Find the first digit
first_digit = next((char for char in input_string if char.isdigit()), None)

# Find the last digit
reversed_string = input_string[::-1]
last_digit = next((char for char in reversed_string if char.isdigit()), None)

return first_digit, last_digit

def get_calib_doc(self):
return self.get_calib_values(self.input)


@timing_decorator
def main(raw, part):
text_input = read_input(raw)
input_parsed = [int(i) if i else "" for i in text_input]
elf_cals = ElfCalories(input_parsed)
input_parsed = [i if i else "" for i in text_input]
calibration = Calibration(input_parsed)
if part == 1:
return elf_cals.get_max(1)
return calibration.get_calib_doc()
elif part == 2:
return elf_cals.get_max(3)
pass
else:
raise ValueError("part must be 1 or 2, instead of: " + part)


def run_tests():
print(f"\nRunning Tests:")
assert main(files["test"], 1) == 24000
assert main(files["test"], 2) == 45000
# assert main(files["test"], 2) == 45000

# solutions
assert main(files["input"], 1) == 66616
assert main(files["input"], 2) == 199172
# assert main(files["input"], 1) == 66616
# assert main(files["input"], 2) == 199172


def run_solution():
print(f"\nRunning Solutions:")
answer1 = main(files["input"], 1)
print(f"Answer part1: {magenta_color}{answer1}{reset_color}")
answer2 = main(files["input"], 2)
print(f"Answer part2: {magenta_color}{answer2}{reset_color}")
# answer2 = main(files["input"], 2)
# print(f"Answer part2: {magenta_color}{answer2}{reset_color}")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 8418e0a

Please sign in to comment.