Skip to content

Bulk Solve Missing LeetCode Problems #2

Bulk Solve Missing LeetCode Problems

Bulk Solve Missing LeetCode Problems #2

Workflow file for this run

name: Bulk Solve Missing LeetCode Problems
on:
workflow_dispatch: # Manual trigger only
inputs:
batch_size:
description: 'Number of problems to solve per run (default: 50)'
required: false
default: '50'
start_index:
description: 'Start from problem at this index in the missing list (0-based, default: 0)'
required: false
default: '0'
jobs:
bulk-solve:
runs-on: ubuntu-latest
if: github.repository_owner == 'ContextLab' # only run if on the ContextLab (source) repository!
permissions:
contents: write # Required to push commits back to the repository
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for proper git operations
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests openai httpx
- name: Identify missing problems
id: find_missing
run: |
# Extract problem numbers from README
grep -oP '\| \[(\d+)\]' README.md | grep -oP '\d+' | sort -n | uniq > /tmp/readme_problems.txt
# Find problems missing gpt5-mini.md
python3 << 'EOF'
from pathlib import Path
with open('/tmp/readme_problems.txt', 'r') as f:
readme_problems = set(int(line.strip()) for line in f if line.strip())
# Check which problems have gpt5-mini.md
problems_dir = Path("problems")
with_ai = set()
for item in problems_dir.iterdir():
if item.is_dir() and item.name.isdigit():
gpt5_file = item / "gpt5-mini.md"
if gpt5_file.exists():
with_ai.add(int(item.name))
# Find problems missing AI solutions
missing_ai = sorted(readme_problems - with_ai)
# Save missing problems
with open('/tmp/missing_ai_solutions.txt', 'w') as f:
for prob in missing_ai:
f.write(f"{prob}\n")
print(f"Total problems in README: {len(readme_problems)}")
print(f"Problems with AI solutions: {len(with_ai)}")
print(f"Problems missing AI solutions: {len(missing_ai)}")
EOF
# Set output for GitHub Actions
MISSING_COUNT=$(wc -l < /tmp/missing_ai_solutions.txt)
echo "total_missing=$MISSING_COUNT" >> $GITHUB_OUTPUT
- name: Create batch file
run: |
START_INDEX=${{ github.event.inputs.start_index }}
BATCH_SIZE=${{ github.event.inputs.batch_size }}
# Extract the batch of problems to solve
tail -n +$((START_INDEX + 1)) /tmp/missing_ai_solutions.txt | head -n $BATCH_SIZE > /tmp/batch_problems.txt
BATCH_COUNT=$(wc -l < /tmp/batch_problems.txt)
echo "Processing batch: $BATCH_COUNT problems starting from index $START_INDEX"
echo "Problems in this batch:"
cat /tmp/batch_problems.txt
- name: Run bulk solver
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python3 auto_solver.py --bulk /tmp/batch_problems.txt
- name: Commit and push changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Bulk solve LeetCode problems (batch starting at index ${{ github.event.inputs.start_index }})"
branch: main
file_pattern: problems/*/gpt5-mini.md