Skip to content

Commit 62786df

Browse files
Refactor and update solutions for Advent of Code 2023 and 2024
- Removed obsolete files and tasks for Day 2 and Day 3 of 2024. - Implemented new logic for handling the Problem Dampener in Day 2, part 2. - Updated Day 3 solutions to incorporate new instructions for enabling/disabling multiplications. - Added new task descriptions for Day 2 and Day 3 of 2024. - Created new scripts for generating progress SVGs and updating README with progress. - Added initial solutions for Day 1 of 2024, including both parts. - Cleaned up and optimized existing code for clarity and performance.
1 parent aa72431 commit 62786df

23 files changed

Lines changed: 175 additions & 1 deletion
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
from pathlib import Path
2+
3+
# --------------------------
4+
# Config
5+
# --------------------------
6+
# For years with fewer than 25 days (the default is 25)
7+
days_per_year = {2025: 12}
8+
9+
SIZE = 28
10+
PADDING = 8
11+
12+
COLOR_EMPTY = "#eeeeee"
13+
COLOR_PART1 = "#2ecc71"
14+
COLOR_BOTH = "#f1c40f" # gold
15+
16+
repo_root = Path(__file__).resolve().parents[2]
17+
graphics_dir = repo_root / ".github/graphics"
18+
graphics_dir.mkdir(parents=True, exist_ok=True)
19+
print(f"Repository root: {repo_root}")
20+
21+
# --------------------------
22+
# SVG generator
23+
# --------------------------
24+
def generate_year_svg(year_dir: Path):
25+
year = year_dir.name
26+
27+
def day_status(day: int) -> str:
28+
day_dir = year_dir / f"Day{day:02d}"
29+
if not day_dir.is_dir():
30+
return "empty"
31+
if (day_dir / "part2.py").exists():
32+
return "both"
33+
if (day_dir / "part1.py").exists():
34+
return "part1"
35+
return "empty"
36+
37+
total_days = days_per_year.get(int(year), 25)
38+
39+
# Layout
40+
COLS = days_per_year.get(int(year), 25)
41+
rows = (total_days + COLS - 1) // COLS
42+
width = COLS * (SIZE + PADDING) + PADDING
43+
height = rows * (SIZE + PADDING) + PADDING
44+
45+
rects = []
46+
for day in range(1, total_days + 1):
47+
row = (day - 1) // COLS
48+
col = (day - 1) % COLS
49+
50+
x = PADDING + col * (SIZE + PADDING)
51+
y = PADDING + row * (SIZE + PADDING)
52+
53+
status = day_status(day)
54+
55+
if status == "both":
56+
color = COLOR_BOTH
57+
title = f"Day {day}: ⭐⭐"
58+
elif status == "part1":
59+
color = COLOR_PART1
60+
title = f"Day {day}: ⭐"
61+
else:
62+
color = COLOR_EMPTY
63+
title = f"Day {day}: not solved"
64+
65+
rects.append(
66+
f'''
67+
<a href="./{year}/Day{day:02d}">
68+
<rect x="{x}" y="{y}"
69+
width="{SIZE}" height="{SIZE}"
70+
rx="6" ry="6"
71+
fill="{color}">
72+
<title>{title}</title>
73+
</rect>
74+
</a>
75+
'''
76+
)
77+
78+
svg = f"""<svg
79+
xmlns="http://www.w3.org/2000/svg"
80+
width="{width}"
81+
height="{height}"
82+
viewBox="0 0 {width} {height}"
83+
>
84+
{"".join(rects)}
85+
</svg>
86+
"""
87+
88+
output = graphics_dir / f"aoc-progress-{year}.svg"
89+
output.write_text(svg)
90+
print(f"Generated {output}")
91+
92+
93+
# --------------------------
94+
# Generate all SVGs
95+
# --------------------------
96+
years_generated = []
97+
for year_dir in repo_root.iterdir():
98+
if year_dir.is_dir() and year_dir.name.isdigit():
99+
generate_year_svg(year_dir)
100+
years_generated.append(year_dir.name)
101+
102+
103+
# --------------------------
104+
# Update README.md automatically
105+
# --------------------------
106+
readme_path = repo_root / "README.md"
107+
start_marker = "<!-- AOC_PROGRESS_START -->"
108+
end_marker = "<!-- AOC_PROGRESS_END -->"
109+
110+
# Default cleared content between markers
111+
default_content = f"{start_marker}\n{end_marker}"
112+
113+
if readme_path.exists():
114+
old_content = readme_path.read_text()
115+
if start_marker in old_content and end_marker in old_content:
116+
# Reset section to default first
117+
pre = old_content.split(start_marker)[0]
118+
post = old_content.split(end_marker)[1]
119+
readme_content = pre + default_content + post
120+
else:
121+
# Append default markers if missing
122+
readme_content = old_content.strip() + "\n\n" + default_content
123+
else:
124+
readme_content = default_content
125+
126+
# Now insert the generated SVGs inside markers
127+
lines = [start_marker, ""]
128+
for year in sorted(years_generated):
129+
lines.append(f"## {year}")
130+
lines.append(f'<p align="center"><img src="./.github/graphics/aoc-progress-{year}.svg" alt="AoC {year} progress"/></p>\n')
131+
lines.append(end_marker)
132+
133+
# Replace the marker section
134+
readme_content = readme_content.split(start_marker)[0] + "\n".join(lines) + readme_content.split(end_marker)[1]
135+
136+
readme_path.write_text(readme_content)
137+
print(f"Updated {readme_path}")

.github/workflows/aoc-progress.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Update Advent of Code progress
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
generate:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: Generate SVGs
23+
run: python .github/scripts/generate_aoc_svg.py
24+
25+
- name: Commit SVGs and README
26+
run: |
27+
git config user.name "github-actions"
28+
git config user.email "github-actions@github.com"
29+
git add aoc-progress-*.svg README.md
30+
git commit -m "Update Advent of Code progress" || exit 0
31+
git push
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)