Skip to content

Commit

Permalink
Merge pull request #82 from wimglenn/2023/02
Browse files Browse the repository at this point in the history
day 02
  • Loading branch information
wimglenn authored Dec 2, 2023
2 parents 8d01637 + c80204a commit c36f2f8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.12"
architecture: x64
cache: "pip"
cache-dependency-path: "pyproject.toml"
- name: "Create release"
cache: pip
cache-dependency-path: pyproject.toml
- name: Create release
run: |
python -VV
python -m pip install -q -U wheel setuptools twine luddite build
Expand Down
28 changes: 28 additions & 0 deletions aoc_wim/aoc2023/q02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
--- Day 2: Cube Conundrum ---
https://adventofcode.com/2023/day/2
"""
from aocd import data

bag = dict(zip("rgb", [12, 13, 14]))
a = b = 0
for line in data.splitlines():
maxs = dict.fromkeys("rgb", 0)
g, line = line.split(": ")
g = int(g.removeprefix("Game "))
handfuls = line.split("; ")
game_possible = True
for handful in handfuls:
counts = dict.fromkeys("rgb", 0)
for n_c in handful.split(", "):
n, c = n_c.split()
counts[c[0]] += int(n)
for c in "rgb":
maxs[c] = max(maxs[c], counts[c])
if any(counts[c] > bag[c] for c in "rgb"):
game_possible = False
a += g * game_possible
b += maxs["r"] * maxs["g"] * maxs["b"]

print("answer_a:", a)
print("answer_b:", b)
10 changes: 5 additions & 5 deletions aoc_wim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ def start():
print("answer_a:", )
print("answer_b:", )
# from aocd import submit; submit(a)
'''))
test = here.parent / "tests" / str(year) / str(day).zfill(2) / "a.txt"
if not test.exists():
Expand All @@ -135,8 +135,8 @@ def start():
[example] = puzzle.examples
if test.read_text() == "\n-\n-\n":
test.write_text(dedent(f"""\
{example.input_data}
{example.answer_a or "-"}
{example.answer_b or "-"}
{example.input_data}
{example.answer_a or "-"}
{example.answer_b or "-"}
"""))
webbrowser.open(puzzle.url)
7 changes: 7 additions & 0 deletions tests/2023/02/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
8
2286

0 comments on commit c36f2f8

Please sign in to comment.