forked from danmax/aoc
DeaDvey d3 optimisations & danmax
This commit is contained in:
6
2025/3/danmax/Cargo.toml
Normal file
6
2025/3/danmax/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "danmax"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
18
2025/3/danmax/src/main.rs
Normal file
18
2025/3/danmax/src/main.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
fn main() {
|
||||
let raw = std::fs::read_to_string("../large.txt").unwrap();
|
||||
let start = std::time::Instant::now();
|
||||
let mut banks = raw.split('\n').collect::<Vec<&str>>();
|
||||
banks.pop();
|
||||
let mut sol = 0;
|
||||
for bank in banks {
|
||||
let batteries = bank.chars().map(|x| (x as u8) - 48).collect::<Vec<u8>>();
|
||||
let mut combos = vec![];
|
||||
for i in 0..batteries.len() - 1 {
|
||||
let num = (batteries[i] * 10) + batteries[(i + 1)..batteries.len()].iter().max().unwrap();
|
||||
combos.push(num);
|
||||
}
|
||||
sol += *combos.iter().max().unwrap() as u64;
|
||||
}
|
||||
let end = start.elapsed();
|
||||
dbg!(sol, end);
|
||||
}
|
||||
Reference in New Issue
Block a user