This commit is contained in:
dolphinau 2025-12-01 13:03:29 +01:00
commit fc496204e7
No known key found for this signature in database
24 changed files with 2758 additions and 0 deletions

9
AoC_2025/src/ansi.rs Normal file
View file

@ -0,0 +1,9 @@
pub const RESET: &str = "\x1b[0m";
pub const BOLD: &str = "\x1b[1m";
pub const RED: &str = "\x1b[31m";
pub const GREEN: &str = "\x1b[32m";
pub const YELLOW: &str = "\x1b[33m";
pub const BLUE: &str = "\x1b[94m";
pub const WHITE: &str = "\x1b[97m";
pub const HOME: &str = "\x1b[H";
pub const CLEAR: &str = "\x1b[J";

22
AoC_2025/src/cli.rs Normal file
View file

@ -0,0 +1,22 @@
use clap::Parser;
use std::ops::RangeInclusive;
const DAY_RANGE: RangeInclusive<usize> = 1..=25;
fn day_in_range(d: &str) -> Result<usize, String> {
let day: usize = d.parse().map_err(|_| format!("`{d}` is not a number."))?;
if DAY_RANGE.contains(&day) {
Ok(day)
} else {
Err(format!(
"`{day}` not in range {}-{}.",
DAY_RANGE.start(),
DAY_RANGE.end()
))
}
}
#[derive(Parser)]
pub struct Cli {
#[arg(help = "day to run", value_parser = day_in_range)]
pub day: usize,
}

View file

@ -0,0 +1,17 @@
use crate::days::Solution;
pub struct Day01;
impl Solution for Day01 {
type Input = ();
fn parse(&self, data: &str) -> Self::Input {}
fn part1(&self, input: &Self::Input) -> usize {
0
}
fn part2(&self, input: &Self::Input) -> usize {
0
}
}

9
AoC_2025/src/days/mod.rs Normal file
View file

@ -0,0 +1,9 @@
pub mod day01;
pub trait Solution {
type Input;
fn parse(&self, data: &str) -> Self::Input;
fn part1(&self, input: &Self::Input) -> usize;
fn part2(&self, input: &Self::Input) -> usize;
}

3
AoC_2025/src/lib.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod ansi;
pub mod cli;
pub mod days;

44
AoC_2025/src/main.rs Normal file
View file

@ -0,0 +1,44 @@
use AoC_2025::{
ansi::{BOLD, RED, RESET, YELLOW},
cli,
days::{self, Solution},
};
use clap::Parser;
use std::{fs::read_to_string, process, time::Instant};
fn run(day: usize, sol: impl Solution) {
let path = format!("input/{day:02}_day.txt");
if let Ok(data) = read_to_string(&path) {
let now = Instant::now();
let input = sol.parse(&data);
let part1 = sol.part1(&input);
let part2 = sol.part2(&input);
let elapsed = now.elapsed();
println!("{YELLOW}------------{RESET}");
println!("{BOLD}{YELLOW} Day {day:02}{RESET}");
println!("{YELLOW}------------{RESET}");
println!("Part1: {part1}");
println!("Part2: {part2}");
println!("Time: {} ns", elapsed.as_nanos());
} else {
println!("{RED}------------{RESET}");
println!("{BOLD}{RED} Day {day:02}{RESET}");
println!("{RED}------------{RESET}");
println!("Cannot read input at \"{path}\"");
}
}
fn main() {
let cli = cli::Cli::parse();
let sol = match cli.day {
1 => days::day01::Day01,
_ => {
eprintln!("Day {:02} is not implemented yet!", cli.day);
process::exit(1);
}
};
run(cli.day, sol);
}