prepare days
This commit is contained in:
parent
5000ae7344
commit
595f4ba264
24 changed files with 253 additions and 27 deletions
0
res/16/example
Normal file
0
res/16/example
Normal file
0
res/17/example
Normal file
0
res/17/example
Normal file
0
res/18/example
Normal file
0
res/18/example
Normal file
0
res/19/example
Normal file
0
res/19/example
Normal file
0
res/20/example
Normal file
0
res/20/example
Normal file
0
res/21/example
Normal file
0
res/21/example
Normal file
0
res/22/example
Normal file
0
res/22/example
Normal file
0
res/23/example
Normal file
0
res/23/example
Normal file
0
res/24/example
Normal file
0
res/24/example
Normal file
0
res/25/example
Normal file
0
res/25/example
Normal file
|
@ -1,6 +1,8 @@
|
|||
use regex::Regex;
|
||||
use std::fs;
|
||||
|
||||
use rayon::prelude::*;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/02/input";
|
||||
|
||||
|
@ -13,7 +15,9 @@ pub fn solve() {
|
|||
|
||||
let result: usize = contents
|
||||
.lines()
|
||||
.map(|line| {
|
||||
.enumerate()
|
||||
.par_bridge()
|
||||
.map(|(i, line)| {
|
||||
let re = Regex::new(r"(\d+) (\w+)").unwrap();
|
||||
let mut col_max = [0, 0, 0];
|
||||
for cap in re.captures_iter(line) {
|
||||
|
@ -27,9 +31,8 @@ pub fn solve() {
|
|||
_ => {}
|
||||
}
|
||||
}
|
||||
col_max
|
||||
(i, col_max)
|
||||
})
|
||||
.enumerate()
|
||||
.filter(|(_, [r, g, b])| *r <= MAX_R && *g <= MAX_G && *b <= MAX_B)
|
||||
.map(|(i, _)| i + 1)
|
||||
.sum();
|
||||
|
@ -37,7 +40,7 @@ pub fn solve() {
|
|||
println!("Result 1: {}", result);
|
||||
|
||||
let result: usize = contents
|
||||
.lines()
|
||||
.par_lines()
|
||||
.map(|line| {
|
||||
let re = Regex::new(r"(\d+) (\w+)").unwrap();
|
||||
let mut col_max = [0, 0, 0];
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn solve() {
|
|||
println!("Result 1: {result}");
|
||||
|
||||
let result: usize = contents
|
||||
.lines()
|
||||
.par_lines()
|
||||
.map(|line| {
|
||||
let (springs_str, nums_str) = line.split_once(" ").unwrap();
|
||||
let nums_tmp: Vec<usize> = nums_str
|
||||
|
|
|
@ -42,9 +42,6 @@ pub fn solve() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
dbg!(&boxes);
|
||||
|
||||
let result: usize = boxes
|
||||
.iter()
|
||||
.map(|(k, v)| {
|
||||
|
|
18
src/days/d16.rs
Normal file
18
src/days/d16.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/16/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d17.rs
Normal file
18
src/days/d17.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/17/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d18.rs
Normal file
18
src/days/d18.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/18/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d19.rs
Normal file
18
src/days/d19.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/19/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d20.rs
Normal file
18
src/days/d20.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/20/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d21.rs
Normal file
18
src/days/d21.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/21/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d22.rs
Normal file
18
src/days/d22.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/22/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d23.rs
Normal file
18
src/days/d23.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/23/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d24.rs
Normal file
18
src/days/d24.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/24/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
18
src/days/d25.rs
Normal file
18
src/days/d25.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use std::fs;
|
||||
|
||||
pub fn solve() {
|
||||
let path = "res/25/example";
|
||||
|
||||
let mut _contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
//let contents = BufReader::new(fs::File::open(path).expect("I/O error, wrong path?"));
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 1: {result}");
|
||||
|
||||
|
||||
let result: usize = 0;
|
||||
|
||||
println!("Result 2: {result}");
|
||||
}
|
84
src/main.rs
84
src/main.rs
|
@ -9,73 +9,119 @@ fn main() {
|
|||
//_all_days()
|
||||
}
|
||||
|
||||
#[allow(unreachable_code, unused)]
|
||||
fn _all_days() {
|
||||
let start = Instant::now();
|
||||
let mut time = start.clone();
|
||||
println!("\nDay 1");
|
||||
days::d01::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 2");
|
||||
days::d02::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 3");
|
||||
days::d03::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 4");
|
||||
days::d04::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 5");
|
||||
days::d05::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 6");
|
||||
days::d06::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 7");
|
||||
days::d07::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 8");
|
||||
days::d08::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 9");
|
||||
days::d09::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 10");
|
||||
days::d10::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 11");
|
||||
days::d11::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 12");
|
||||
days::d12::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 13");
|
||||
days::d13::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 14");
|
||||
days::d14::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 15");
|
||||
days::d15::solve();
|
||||
print_elapsed(&start);
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 16");
|
||||
days::d16::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
/*
|
||||
println!("\nDay 17");
|
||||
days::d17::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 18");
|
||||
days::d18::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 19");
|
||||
days::d19::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 20");
|
||||
days::d20::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 21");
|
||||
days::d21::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 22");
|
||||
days::d22::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 23");
|
||||
days::d23::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 24");
|
||||
days::d24::solve();
|
||||
time = _print_elapsed(time);
|
||||
|
||||
println!("\nDay 25");
|
||||
days::d25::solve();
|
||||
_print_elapsed(time);*/
|
||||
|
||||
println!("\nTotal elapsed: {}ms", start.elapsed().as_millis())
|
||||
}
|
||||
|
||||
fn print_elapsed(start: &Instant) {
|
||||
fn _print_elapsed(time: Instant) -> Instant {
|
||||
println!(
|
||||
" Elapsed: {}.{}ms",
|
||||
start.elapsed().as_millis(),
|
||||
start.elapsed().as_micros() % 1000
|
||||
)
|
||||
time.elapsed().as_millis(),
|
||||
time.elapsed().as_micros() % 1000
|
||||
);
|
||||
Instant::now()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue