Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
[flake8]
max-line-length=100
import-order-style=pycharm
extend-ignore=
# pycodestyle
E203,E226,E701
E,F,W,
# flake8-annotations
ANN002,ANN003,ANN101,ANN102,ANN204,ANN206,
extend-exclude=
.venv,
per-file-ignores =
test_*.py:E501,
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ ci:
autoupdate_schedule: quarterly

repos:
- repo: https://github.com/psf/black
rev: 25.1.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.9.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 6.0.1
rev: 6.1.0
hooks:
- id: isort
name: isort
Expand All @@ -18,7 +18,7 @@ repos:
additional_dependencies:
- flake8-annotations
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -40,6 +40,6 @@ repos:
- id: matlab-reflow-comments
args: [--line-length=100]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.2
rev: v0.14.0
hooks:
- id: ruff-check
3 changes: 3 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"D", # pydocstyle/flake8-docstrings
"E", # pycodestyle
"F", # Pyflakes
"FIX", # flake8-fixme
"N", # pep8-naming
"W", # pycodestyle
]

ignore = [
Expand Down Expand Up @@ -58,5 +60,6 @@ ignore = [
"test_*.py" = [
"D101",
"D103",
"E501",
]
"2021/Day_18/aoc_2021_day18.py" = ["D202"]
16 changes: 8 additions & 8 deletions 2021/Day_14/aoc_2021_day14.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def calculate_spread(polymer: str) -> int:
# How about a smarter not harder approach instead
def non_brute_deconstruct(template: str, rules: dict[str, str], n_cycles: int) -> int:
"""Calculate the element spread of the provided polymer after the target insertion cycle(s)."""
l: str
r: str
left: str
right: str

# Since we don't care about order, we can keep track of the pairs created by each step and
# use these counts to determine element counts once we run through all of the insertion cycles
Expand All @@ -80,12 +80,12 @@ def non_brute_deconstruct(template: str, rules: dict[str, str], n_cycles: int) -
for _ in range(n_cycles):
updated_pairs: Counter[str] = Counter()
for pair, count in pairs_counter.items():
l, r = pair
left, right = pair
# Each pair will add the corresponding number of pairs composed of the inserted element
# and the left/right sides
# This will end up double counting the middle element but we can fix that later
updated_pairs[f"{l}{rules[pair]}"] += count
updated_pairs[f"{rules[pair]}{r}"] += count
updated_pairs[f"{left}{rules[pair]}"] += count
updated_pairs[f"{rules[pair]}{right}"] += count

# Now that we've updated our pairs we can replace our starting point
pairs_counter = updated_pairs
Expand All @@ -94,9 +94,9 @@ def non_brute_deconstruct(template: str, rules: dict[str, str], n_cycles: int) -
# quantities. As noted above, our inserted elements have all been double counted, except for the
# first & last elements. So we can just double the first & last and divide the counts by 2.
element_counts: Counter[str] = Counter()
for (l, r), count in pairs_counter.items():
element_counts[l] += count
element_counts[r] += count
for (left, right), count in pairs_counter.items():
element_counts[left] += count
element_counts[right] += count
element_counts[template[0]] += 1
element_counts[template[-1]] += 1

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ Repository = "https://github.com/sco1/adventofcode"
aoc-init = "helpers.init_puzzle:main"
set-prog = "helpers.update_progress:main"

[tool.uv]
dev-dependencies = [
[dependency-groups]
dev = [
"black~=25.0",
"cogapp~=3.4",
"flake8~=7.1",
"flake8-annotations~=3.1",
"flake8-define-class-attributes~=0.2",
"isort~=6.0",
"mypy~=1.11",
"pre-commit~=4.0",
Expand Down
Loading