Skip to content

Commit b25fb00

Browse files
committed
improvements
1 parent cef11bc commit b25fb00

File tree

25 files changed

+328
-174
lines changed

25 files changed

+328
-174
lines changed

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[package]
22
name = "one"
3-
version = "0.1.0"
3+
version = "1.1.0"
44
edition = "2021"
5+
license = "Unlicense"
6+
repository = "https://github.com/rene-d/advent-of-rust"
57

68
[features]
79
ascii = []
@@ -42,3 +44,7 @@ geo = "*"
4244
geo-types = "*"
4345
bytecount = "*"
4446
divisors = "*"
47+
48+
[lints.clippy]
49+
pedantic = "forbid"
50+
nursery = "forbid"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Puzzle | Stars |
4545
Calendar | Solutions | Stars | Rust | Python | 🎁
4646
-------- | --------- | ----- | ---- | ------ | --
4747
[Advent of Code 2024](https://adventofcode.com/2024) | [Solutions](src/year2024/README.md) | 50⭐ | 25 | 10 | 3
48-
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 11 | 1
48+
[Advent of Code 2023](https://adventofcode.com/2023) | [Solutions](src/year2023/README.md) | 50⭐ | 25 | 11 | 2
4949
[Advent of Code 2022](https://adventofcode.com/2022) | [Solutions](src/year2022/README.md) | 50⭐ | 25 | 18 | 1
5050
[Advent of Code 2021](https://adventofcode.com/2021) | [Solutions](src/year2021/README.md) | 50⭐ | 25 | 12 |
5151
[Advent of Code 2020](https://adventofcode.com/2020) | [Solutions](src/year2020/README.md) | 50⭐ | 25 | 23 |
@@ -60,7 +60,7 @@ Calendar | Solutions | Stars | Rust | Python | 🎁
6060
Year | Count | Days
6161
---- | ----- | --------------------
6262
2024 | 3 | [14](src/year2024/day14/README.md) [15](src/year2024/day15/README.md) [16](src/year2024/day16/README.md)
63-
2023 | 1 | [10](src/year2023/day10/README.md)
63+
2023 | 2 | [10](src/year2023/day10/README.md) [14](src/year2023/day14/README.md)
6464
2022 | 1 | [17](src/year2022/day17/README.md)
6565
2019 | 2 | [13](src/year2019/day13/README.md) [15](src/year2019/day15/README.md)
6666
2018 | 1 | [18](src/year2018/day18/README.md)

crates/aoc/src/args.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use crate::load_input_data;
88

99
#[derive(Debug)]
1010
pub struct Args {
11-
pub input: String, // puzzle input
12-
pub verbose: bool, // activate the verbose flag
13-
options: Vec<String>, // copy of Args() (with a leading -)
14-
pub params: Vec<String>, // copy of Args() (without the leading -)
15-
elapsed: bool, // flag to show elapsed time
11+
input: String, // puzzle input
12+
verbose: bool, // activate the verbose flag
13+
options: Vec<String>, // copy of Args() (with a leading -)
14+
params: Vec<String>, // copy of Args() (without the leading -)
15+
elapsed: bool, // flag to show elapsed time
1616
}
1717

1818
impl Args {
@@ -27,6 +27,15 @@ impl Args {
2727
args
2828
}
2929

30+
pub const fn input(&self) -> &String {
31+
&self.input
32+
}
33+
34+
/// Return `true` if the flag -v/--verbose is on commandline.
35+
pub const fn is_verbose(&self) -> bool {
36+
self.verbose
37+
}
38+
3039
#[must_use]
3140
pub fn parse_args_raw() -> Self {
3241
let help = std::env::args().any(|a| a == "--help" || a == "-h");
@@ -56,6 +65,10 @@ impl Args {
5665
self.options.iter().filter(|s| *s == option).count() != 0
5766
//self.options.contains(option)
5867
}
68+
69+
pub fn params(&self) -> &[String] {
70+
self.params.as_slice()
71+
}
5972
}
6073

6174
/// Show command-line usage.
@@ -107,8 +120,8 @@ impl Args {
107120

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

110-
#[allow(clippy::cast_possible_truncation)]
111-
let micros = Duration::from_micros(instant.elapsed().as_micros() as u64);
123+
let elapsed = instant.elapsed();
124+
let micros = Duration::new(elapsed.as_secs(), elapsed.subsec_micros() * 1000);
112125

113126
println!("{p1}");
114127

crates/aoc/src/bin/dayXX/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::time::Duration;
33
fn main() {
44
let args = aoc::parse_args();
55

6-
if args.verbose {
6+
if args.is_verbose() {
77
println!("{args:#?}");
88
}
99

crates/assembunny/src/bin/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use assembunny::BunnyVM;
55
fn main() {
66
let args = aoc::parse_args();
77

8-
let mut vm = BunnyVM::new(&args.input);
8+
let mut vm = BunnyVM::new(args.input());
99
let output = vm.run_output(usize::MAX);
1010

1111
println!("{:?}", vm.registers);

crates/intcode/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() {
22
let args = aoc::parse_args();
33

4-
let program = intcode::Computer::load(&args.input);
4+
let program = intcode::Computer::load(args.input());
55

66
println!("{program}");
77
}

scripts/runall.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,18 @@ def run(
165165

166166
cmd = []
167167

168-
f = Path("src/year{year}/day{day}/day{day}/target/release/day{day}")
168+
f = Path(f"{prog.parent}/{prog.stem}/target/release/{prog.stem}")
169169
if f.is_file():
170170
cmd.append(f)
171171
else:
172172
cmd.append("target/release/one")
173173
cmd.append("-r")
174-
cmd.append(f"{year}:{day}")
174+
175+
alt = re.match(r"day\d+_(\w+)$", prog.stem)
176+
if alt:
177+
cmd.append(f"{year}:{day}:{alt[1]}")
178+
else:
179+
cmd.append(f"{year}:{day}")
175180

176181
else:
177182

src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use itertools::Itertools;
44

55
/// Get the array of all available solutions.
66
#[must_use]
7-
pub fn solutions() -> Vec<Solution> {
8-
empty()
7+
pub fn solutions(year: Option<u16>, day: Option<u8>, alt: &Option<String>) -> Vec<Solution> {
8+
let sols = empty()
99
.chain(year2015())
1010
.chain(year2016())
1111
.chain(year2017())
@@ -15,7 +15,11 @@ pub fn solutions() -> Vec<Solution> {
1515
.chain(year2021())
1616
.chain(year2022())
1717
.chain(year2023())
18-
.chain(year2024())
18+
.chain(year2024());
19+
20+
sols.filter(|sol| year.is_none_or(|x| x == sol.year))
21+
.filter(|sol| day.is_none_or(|x| x == sol.day))
22+
.filter(|sol| alt == &Some("*".to_string()) || alt == &sol.alt)
1923
.sorted_unstable_by_key(|sol| (sol.year, sol.day, sol.alt.is_some()))
2024
.collect()
2125
}
@@ -45,9 +49,13 @@ macro_rules! make_year {
4549
let year = stringify!($year)[4..].parse().unwrap();
4650
let day = &stringify!($day)[3..];
4751

48-
let (day, alt) = day.split_once('_').map_or((day,None), |(day,alt)| (day,Some(alt.to_string())) );
52+
let (day, alt) = day
53+
.split_once('_')
54+
.map_or((day, None), |(day, alt)| (day, Some(alt.to_string())));
4955
let day = day.parse().unwrap();
5056

57+
// eprintln!("=> {year} {day} {alt:?}");
58+
5159
let solve = |data: &str| {
5260
use crate::$year::$day::$day::solve;
5361
let (part1, part2) = solve(data);

0 commit comments

Comments
 (0)