let monkeys = day11::parse(&fs::read_to_string("data/day11.input").unwrap());
format!(
"part1: {}, part2: {}",
- day11::run(&mut monkeys.clone(), 20, 3),
- day11::run(&mut monkeys.clone(), 10000, 1)
+ day11::run::<3>(&mut monkeys.clone(), 20),
+ day11::run::<1>(&mut monkeys.clone(), 10000)
)
}
day12::nb_steps(&heightmap, day12::Path::EndTo0Elevation)
)
}
+
+pub fn day13() -> String {
+ let signals = day13::parse(&fs::read_to_string("data/day13.input").unwrap());
+ format!(
+ "part1: {}, part2: {}",
+ day13::sum_indices_signals_in_the_right_order(&signals),
+ day13::product_indices_special_signals(&signals)
+ )
+}
-use std::{env, time::Instant};
+use std::time::Instant;
+
+use clap::Parser;
+use rayon::prelude::*;
mod day01;
mod day02;
mod day10;
mod day11;
mod day12;
+mod day13;
mod days;
+#[derive(Parser, Debug)]
+#[command(author = "Greg Burri", version = "1.0", about = "Advent of Code 2022")]
+struct Args {
+ #[arg(index(1), exclusive(true))]
+ day: Option<usize>,
+
+ #[arg(short, long)]
+ parallel: bool,
+}
+
fn main() {
println!("https://adventofcode.com/2022");
days::day10,
days::day11,
days::day12,
+ days::day13,
];
- let args: Vec<String> = env::args().skip(1).collect();
+ let args = Args::parse();
- // No argument -> execute all day problems.
- if args.is_empty() {
- let now = Instant::now();
- for i in 1..=days.len() {
- do_day(&days, i)
+ match args.day {
+ Some(day) => {
+ if day >= 1 && day <= days.len() {
+ do_day(&days, day)
+ } else {
+ println!("Unknown day: {}", day)
+ }
}
- println!(
- "Time to execute all days: {}",
- format_micros(now.elapsed().as_micros())
- );
- } else {
- for arg in args {
- match arg.parse::<usize>() {
- Ok(day) if day >= 1 && day <= days.len() => do_day(&days, day),
- Ok(day) => println!("Unknown day: {}", day),
- Err(error) => println!("Unable to parse day number: \"{}\", error: {}", arg, error),
+ // No argument -> execute all day problems.
+ None => {
+ let now = Instant::now();
+
+ if args.parallel {
+ (1..=days.len())
+ .into_par_iter()
+ .for_each(|d| do_day(&days, d));
+ } else {
+ (1..=days.len()).for_each(|d| do_day(&days, d));
}
+
+ println!(
+ "Time to execute all days: {}",
+ format_micros(now.elapsed().as_micros())
+ );
}
}
}