Skip to content

Commit

Permalink
Merge pull request #81 from wimglenn/2023/01
Browse files Browse the repository at this point in the history
day 01
  • Loading branch information
wimglenn authored Dec 1, 2023
2 parents c6aa68c + 6c9fd37 commit 8d01637
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "3.11"
python-version: "3.12"
architecture: x64
cache: "pip"
cache-dependency-path: "pyproject.toml"
Expand Down
25 changes: 12 additions & 13 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ on:

jobs:
tests:
name: "Python ${{ matrix.python-version }} on ${{ matrix.os }}"
name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
python-version: ${{ matrix.python-version }}
architecture: x64
cache: "pip"
cache-dependency-path: "pyproject.toml"
- name: "Install"
cache: pip
cache-dependency-path: pyproject.toml
- name: Install
run: |
python -VV
python -m pip install -U pip setuptools wheel
python -m pip install pytest>=7rc1 pytest-socket --editable .
python -m pip freeze --all
- name: "Run tests for ${{ matrix.python-version }} on ${{ matrix.os }}"
run: python -m pytest -v --durations=10 --disable-socket
python -m pip install -q pytest>=7 pytest-socket --editable .
python -m pip list
- name: Run tests for ${{ matrix.python-version }} on ${{ matrix.os }}
run: pytest -v --durations=10 --disable-socket
Empty file added aoc_wim/aoc2023/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions aoc_wim/aoc2023/q01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
--- Day 1: Trebuchet?! ---
https://adventofcode.com/2023/day/1
"""
import regex as re
from aocd import data

ns = "one, two, three, four, five, six, seven, eight, nine".split(", ")
d = dict(zip(ns, "123456789"))
a = b = 0
pat_a = re.compile(r"\d")
pat_b = re.compile(rf"(\d|{'|'.join(ns)})")
for line in data.splitlines():
nums_a = [int(x) for x in pat_a.findall(line)] or [0]
nums_b = [int(d.get(x, x)) for x in pat_b.findall(line, overlapped=True)] or [0]
a += nums_a[0] * 10 + nums_a[-1]
b += nums_b[0] * 10 + nums_b[-1]

print("answer_a:", a)
print("answer_b:", b)
7 changes: 6 additions & 1 deletion aoc_wim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ def start():
print(data)
set_docstrings([src])
puzzle = Puzzle(year, day)
[example] = puzzle.examples
if test.read_text() == "\n-\n-\n":
test.write_text("{}\n-\n-\n".format(puzzle.example_data))
test.write_text(dedent(f"""\
{example.input_data}
{example.answer_a or "-"}
{example.answer_b or "-"}
"""))
webbrowser.open(puzzle.url)
6 changes: 6 additions & 0 deletions tests/2023/01/a.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
142
-
9 changes: 9 additions & 0 deletions tests/2023/01/b.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
-
281

0 comments on commit 8d01637

Please sign in to comment.