Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-d committed Jan 26, 2025
1 parent cef11bc commit b25fb00
Show file tree
Hide file tree
Showing 25 changed files with 328 additions and 174 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[package]
name = "one"
version = "0.1.0"
version = "1.1.0"
edition = "2021"
license = "Unlicense"
repository = "https://github.com/rene-d/advent-of-rust"

[features]
ascii = []
Expand Down Expand Up @@ -42,3 +44,7 @@ geo = "*"
geo-types = "*"
bytecount = "*"
divisors = "*"

[lints.clippy]
pedantic = "forbid"
nursery = "forbid"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Puzzle | Stars |
Calendar | Solutions | Stars | Rust | Python | 🎁
-------- | --------- | ----- | ---- | ------ | --
[Advent of Code 2024](https://adventofcode.com/2024) | [Solutions](src/year2024/README.md) | 50⭐ | 25 | 10 | 3
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 11 | 1
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 11 | 2
[Advent of Code 2022](https://adventofcode.com/2022) | [Solutions](src/year2022/README.md) | 50⭐ | 25 | 18 | 1
[Advent of Code 2021](https://adventofcode.com/2021) | [Solutions](src/year2021/README.md) | 50⭐ | 25 | 12 |
[Advent of Code 2020](https://adventofcode.com/2020) | [Solutions](src/year2020/README.md) | 50⭐ | 25 | 23 |
Expand All @@ -60,7 +60,7 @@ Calendar | Solutions | Stars | Rust | Python | 🎁
Year | Count | Days
---- | ----- | --------------------
2024 | 3 | [14](src/year2024/day14/README.md) [15](src/year2024/day15/README.md) [16](src/year2024/day16/README.md)
2023 | 1 | [10](src/year2023/day10/README.md)
2023 | 2 | [10](src/year2023/day10/README.md) [14](src/year2023/day14/README.md)
2022 | 1 | [17](src/year2022/day17/README.md)
2019 | 2 | [13](src/year2019/day13/README.md) [15](src/year2019/day15/README.md)
2018 | 1 | [18](src/year2018/day18/README.md)
Expand Down
27 changes: 20 additions & 7 deletions crates/aoc/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use crate::load_input_data;

#[derive(Debug)]
pub struct Args {
pub input: String, // puzzle input
pub verbose: bool, // activate the verbose flag
options: Vec<String>, // copy of Args() (with a leading -)
pub params: Vec<String>, // copy of Args() (without the leading -)
elapsed: bool, // flag to show elapsed time
input: String, // puzzle input
verbose: bool, // activate the verbose flag
options: Vec<String>, // copy of Args() (with a leading -)
params: Vec<String>, // copy of Args() (without the leading -)
elapsed: bool, // flag to show elapsed time
}

impl Args {
Expand All @@ -27,6 +27,15 @@ impl Args {
args
}

pub const fn input(&self) -> &String {
&self.input
}

/// Return `true` if the flag -v/--verbose is on commandline.
pub const fn is_verbose(&self) -> bool {
self.verbose
}

#[must_use]
pub fn parse_args_raw() -> Self {
let help = std::env::args().any(|a| a == "--help" || a == "-h");
Expand Down Expand Up @@ -56,6 +65,10 @@ impl Args {
self.options.iter().filter(|s| *s == option).count() != 0
//self.options.contains(option)
}

pub fn params(&self) -> &[String] {
self.params.as_slice()
}
}

/// Show command-line usage.
Expand Down Expand Up @@ -107,8 +120,8 @@ impl Args {

let (p1, p2) = solve(data);

#[allow(clippy::cast_possible_truncation)]
let micros = Duration::from_micros(instant.elapsed().as_micros() as u64);
let elapsed = instant.elapsed();
let micros = Duration::new(elapsed.as_secs(), elapsed.subsec_micros() * 1000);

println!("{p1}");

Expand Down
2 changes: 1 addition & 1 deletion crates/aoc/src/bin/dayXX/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
fn main() {
let args = aoc::parse_args();

if args.verbose {
if args.is_verbose() {
println!("{args:#?}");
}

Expand Down
2 changes: 1 addition & 1 deletion crates/assembunny/src/bin/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use assembunny::BunnyVM;
fn main() {
let args = aoc::parse_args();

let mut vm = BunnyVM::new(&args.input);
let mut vm = BunnyVM::new(args.input());
let output = vm.run_output(usize::MAX);

println!("{:?}", vm.registers);
Expand Down
2 changes: 1 addition & 1 deletion crates/intcode/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
let args = aoc::parse_args();

let program = intcode::Computer::load(&args.input);
let program = intcode::Computer::load(args.input());

println!("{program}");
}
9 changes: 7 additions & 2 deletions scripts/runall.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,18 @@ def run(

cmd = []

f = Path("src/year{year}/day{day}/day{day}/target/release/day{day}")
f = Path(f"{prog.parent}/{prog.stem}/target/release/{prog.stem}")
if f.is_file():
cmd.append(f)
else:
cmd.append("target/release/one")
cmd.append("-r")
cmd.append(f"{year}:{day}")

alt = re.match(r"day\d+_(\w+)$", prog.stem)
if alt:
cmd.append(f"{year}:{day}:{alt[1]}")
else:
cmd.append(f"{year}:{day}")

else:

Expand Down
16 changes: 12 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use itertools::Itertools;

/// Get the array of all available solutions.
#[must_use]
pub fn solutions() -> Vec<Solution> {
empty()
pub fn solutions(year: Option<u16>, day: Option<u8>, alt: &Option<String>) -> Vec<Solution> {
let sols = empty()
.chain(year2015())
.chain(year2016())
.chain(year2017())
Expand All @@ -15,7 +15,11 @@ pub fn solutions() -> Vec<Solution> {
.chain(year2021())
.chain(year2022())
.chain(year2023())
.chain(year2024())
.chain(year2024());

sols.filter(|sol| year.is_none_or(|x| x == sol.year))
.filter(|sol| day.is_none_or(|x| x == sol.day))
.filter(|sol| alt == &Some("*".to_string()) || alt == &sol.alt)
.sorted_unstable_by_key(|sol| (sol.year, sol.day, sol.alt.is_some()))
.collect()
}
Expand Down Expand Up @@ -45,9 +49,13 @@ macro_rules! make_year {
let year = stringify!($year)[4..].parse().unwrap();
let day = &stringify!($day)[3..];

let (day, alt) = day.split_once('_').map_or((day,None), |(day,alt)| (day,Some(alt.to_string())) );
let (day, alt) = day
.split_once('_')
.map_or((day, None), |(day, alt)| (day, Some(alt.to_string())));
let day = day.parse().unwrap();

// eprintln!("=> {year} {day} {alt:?}");

let solve = |data: &str| {
use crate::$year::$day::$day::solve;
let (part1, part2) = solve(data);
Expand Down
Loading

0 comments on commit b25fb00

Please sign in to comment.