Rust solutions for Advent of Code puzzles with a beautiful Ratatui TUI interface and automatic day discovery.
- 🎨 Beautiful TUI - Full-featured terminal UI with Ratatui
- 🔍 Auto-Discovery - Automatically detects available days from source files
- 📝 Smart Parsing - Extracts day titles from code comments
- 🚀 CLI Mode - Quick command-line interface for scripting
- 📁 Flexible Input - Support for files, default files, or stdin
- 🎯 Zero Config - No need to manually register days in main.rs
- ⚡ Fast - Written in Rust for maximum performance
# Clone and build
git clone <your-repo>
cd adventcode
cargo build --release
# Run the interactive TUI (just run with no args!)
cargo run
# Or run a specific day directly
cargo run -- --day 5 --part2╔════════════════════════════════════════╗
║ ║
║ 🎄 Advent of Code Runner 🎄 ║
║ ║
╚════════════════════════════════════════╝
┌ Available Days ───────────────────────┐
│ ▶ Day 1: COMBINATION LOCK [✓] │
│ Day 2: INVALID ID DETECTION [✓] │
│ Day 3: LOBBY BATTERIES [✓] │
│ Day 4: PRINTING DEPARTMENT [✓] │
│ Day 5: CAFETERIA [✓] │
└───────────────────────────────────────┘
↑↓: Navigate | Enter: Select | q: Quit
┌──────────────────────────────────────┐
│ Day 5: CAFETERIA │
└──────────────────────────────────────┘
┌ Select Part ─────────────────────────┐
│ │
│ ▶ Part 1 │
│ │
│ Part 2 │
└──────────────────────────────────────┘
↑↓: Select Part | Enter: Run | Backspace: Back | q: Quit
Simply run without any arguments:
cargo runNavigation:
↑/↓ork/j- Navigate through days/partsEnter- Select day or run puzzleBackspace- Go back to day selectionqorEsc- Quit
The TUI will show:
- All available days with their titles (auto-detected!)
- Input file status (✓ if exists, ✗ if missing)
- Beautiful interface with syntax highlighting
Run a specific day with explicit arguments:
# Part 1 with default input file (day1.txt)
cargo run -- --day 1
# Part 2 with custom input file
cargo run -- --day 1 --file input.txt --part2
# Quiet mode (no formatting, just output)
cargo run -- --day 1 --file input.txt --quietcargo run -- -d 1 # Day 1, Part 1, default file
cargo run -- -d 1 -2 # Day 1, Part 2, default file
cargo run -- -d 1 -f input.txt # Day 1, Part 1, custom file
cargo run -- -d 5 -2 -q # Day 5, Part 2, quiet modePipe input directly:
cat input.txt | cargo run -- -d 1 -q
echo "L68\nR30" | cargo run -- -d 1 -2 -q
cargo run -- -d 1 -q < input.txtView all available options:
cargo run -- --helpNo more manual registration! Just create your day file and it's automatically detected.
Create src/dayN.rs with the proper header format:
// ============================================================================
// DAY N: YOUR TITLE HERE
// ============================================================================
//
// PROBLEM OVERVIEW:
// -----------------
// Description of the problem...
//
// Part 1: What part 1 asks for
// Part 2: What part 2 asks for
//
// ============================================================================
pub fn solve(input: &str, part2: bool) {
if part2 {
// Part 2 logic
println!("{}", result);
} else {
// Part 1 logic
println!("{}", result);
}
}Important: The title is extracted from the comment // DAY N: YOUR TITLE
Just add ONE line to the top of src/main.rs:
mod dayN;And add ONE match arm:
match day {
// ...
N => dayN::solve(&input, part2),
_ => eprintln!("Day {} not implemented yet", day),
}Create dayN.txt with your puzzle input.
The system will automatically:
- ✅ Detect the new day exists
- ✅ Extract the title from comments
- ✅ Check if input file exists
- ✅ Show it in the TUI menu
- ✅ Allow you to run it
No need to update:
- ❌ Day lists
- ❌ Menu items
- ❌ Title arrays
- ❌ Configuration files
The system scans src/ for files matching day*.rs (day1.rs through day25.rs) and:
- Detects existence - Checks which day files are present
- Extracts titles - Parses the header comment
// DAY N: TITLE - Checks input - Verifies if
dayN.txtexists - Populates TUI - Automatically shows all found days
The title is extracted using regex pattern:
// DAY \d+: (.+)Examples:
// DAY 5: CAFETERIA → Title: "CAFETERIA"
// DAY 1: COMBINATION LOCK → Title: "COMBINATION LOCK"
// DAY 10: SUPER COOL PUZZLE → Title: "SUPER COOL PUZZLE"By default, the program looks for dayN.txt files:
- Use default files: Place input in
day1.txt,day2.txt, etc. - Specify custom file: Use
--file custom.txt - Use stdin: Pipe input when file doesn't exist
The TUI shows input status:
[✓]- Input file exists[✗]- No input file (will prompt or use stdin)
────────────────────────────────────────────────────────────
🎄 Day 5: CAFETERIA │ Part 2
────────────────────────────────────────────────────────────
Result: 357907198933892
357907198933892
adventcode/
├── src/
│ ├── main.rs # Auto-discovering CLI and TUI
│ ├── day1.rs # Day 1: COMBINATION LOCK
│ ├── day2.rs # Day 2: INVALID ID DETECTION
│ ├── day3.rs # Day 3: LOBBY BATTERIES
│ ├── day4.rs # Day 4: PRINTING DEPARTMENT
│ ├── day5.rs # Day 5: CAFETERIA
│ └── ... # Add more days as needed
├── day1.txt # Input files (optional)
├── day2.txt
├── day3.txt
├── day4.txt
├── day5.txt
├── demo.sh # Demo script
├── Cargo.toml
└── README.md
| Day | Title | Part 1 | Part 2 | Status |
|---|---|---|---|---|
| 1 | Combination Lock | ⭐ | ⭐ | ✅ |
| 2 | Invalid ID Detection | ⭐ | ⭐ | ✅ |
| 3 | Lobby Batteries | ⭐ | ⭐ | ✅ |
| 4 | Printing Department | ⭐ | ⭐ | ✅ |
| 5 | Cafeteria | ⭐ | ⭐ | ✅ |
- Day 1: COMBINATION LOCK - Circular dial rotation with position tracking
- Day 2: INVALID ID DETECTION - Finding repeated digit sequences in numeric ranges
- Day 3: LOBBY BATTERIES - Maximum joltage from battery digit combinations
- Day 4: PRINTING DEPARTMENT - Grid-based paper roll accessibility counting
- Day 5: CAFETERIA - Fresh ingredient ID range merging and counting
- clap (v4.5) - Command-line argument parsing
- ratatui (v0.29) - Terminal user interface library
- crossterm (v0.28) - Terminal manipulation
- regex (v1.11) - Pattern matching for auto-discovery
Unlike traditional Advent of Code runners, this project:
- No manual registration - Just create
dayN.rsand it's detected - Smart title extraction - Parses your code comments automatically
- Input validation - Shows which days have input files ready
- Professional terminal interface
- Smooth keyboard navigation
- Color-coded status indicators
- Responsive layout
- Add days in seconds, not minutes
- Consistent code structure
- Comprehensive documentation in each file
- Easy to extend and maintain
This project demonstrates:
- ✅ Rust module system and project structure
- ✅ File system operations and regex parsing
- ✅ TUI development with Ratatui
- ✅ CLI design with clap
- ✅ Pattern matching and error handling
- ✅ Clean code organization
MIT
Feel free to:
- Add more days (it's automatic!)
- Improve solutions
- Enhance the TUI
- Add features
- Fix bugs
Made with ❤️ and 🦀 Rust