reduced overhead by passing an owned string

This commit is contained in:
2025-12-13 22:20:54 +01:00
parent 0a08ad2cae
commit 2eddd7fdc2
36 changed files with 66 additions and 66 deletions

View File

@@ -1,27 +1,27 @@
# Advent of Code 2025 # Advent of Code 2025
```bash ```bash
day01:A => 1150 ( 98us) day01:A => 1150 ( 35us)
day01:B => 1150 ( 100us) day01:B => 1150 ( 34us)
day02:A => 31839939622 ( 13822us) day02:A => 31839939622 ( 5852us)
day02:B => 41662374059 (128425us) day02:B => 41662374059 ( 49642us)
day03:A => 16812 ( 119us) day03:A => 16812 ( 45us)
day03:B => 166345822896410 ( 357us) day03:B => 166345822896410 ( 136us)
day04:A => 1518 ( 321us) day04:A => 1518 ( 133us)
day04:B => 8665 ( 5870us) day04:B => 8665 ( 2174us)
day05:A => 701 ( 310us) day05:A => 701 ( 111us)
day05:B => 352340558684863 ( 36us) day05:B => 352340558684863 ( 13us)
day06:A => 6503327062445 ( 266us) day06:A => 6503327062445 ( 113us)
day06:B => 9640641878593 ( 145us) day06:B => 9640641878593 ( 53us)
day07:A => 1678 ( 57us) day07:A => 1678 ( 22us)
day07:B => 357525737893560 ( 70us) day07:B => 357525737893560 ( 28us)
day08:A => 0 ( 0us) day08:A => 0 ( 0us)
day08:B => 0 ( 0us) day08:B => 0 ( 0us)
day09:A => 4725826296 ( 236us) day09:A => 4725826296 ( 105us)
day09:B => 0 ( 0us) day09:B => 0 ( 0us)
day10:A => 452 ( 667us) day10:A => 452 ( 271us)
day10:B => 0 ( 0us) day10:B => 0 ( 0us)
day11:A => 636 ( 491us) day11:A => 636 ( 192us)
day11:B => 636 ( 421us) day11:B => 636 ( 162us)
---------- ----------
152155us 59331us
``` ```

View File

@@ -18,11 +18,11 @@ L82";
#[test] #[test]
fn part01a() { fn part01a() {
assert_eq!(part01a::solve(PUZZLE.to_string()), 3); assert_eq!(part01a::solve(PUZZLE), 3);
} }
#[test] #[test]
fn part01b() { fn part01b() {
assert_eq!(part01b::solve(PUZZLE.to_string()), 6); assert_eq!(part01b::solve(PUZZLE), 6);
} }
} }

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
let mut dial: i32 = 50; let mut dial: i32 = 50;

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
let mut dial: i32 = 50; let mut dial: i32 = 50;

View File

@@ -9,11 +9,11 @@ mod tests {
#[test] #[test]
fn part02a() { fn part02a() {
assert_eq!(part02a::solve(PUZZLE.to_string()), 1227775554); assert_eq!(part02a::solve(PUZZLE), 1227775554);
} }
#[test] #[test]
fn part02b() { fn part02b() {
assert_eq!(part02b::solve(PUZZLE.to_string()), 4174379265); assert_eq!(part02b::solve(PUZZLE), 4174379265);
} }
} }

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
puzzle.split(",").for_each(|id_range| { puzzle.split(",").for_each(|id_range| {

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
puzzle.split(",").for_each(|id_range| { puzzle.split(",").for_each(|id_range| {

View File

@@ -12,11 +12,11 @@ mod tests {
#[test] #[test]
fn part03a() { fn part03a() {
assert_eq!(part03a::solve(PUZZLE.to_string()), 357); assert_eq!(part03a::solve(PUZZLE), 357);
} }
#[test] #[test]
fn part03b() { fn part03b() {
assert_eq!(part03b::solve(PUZZLE.to_string()), 3121910778619); assert_eq!(part03b::solve(PUZZLE), 3121910778619);
} }
} }

View File

@@ -1,6 +1,6 @@
use iter_first_max::IterFirstMaxExt; use iter_first_max::IterFirstMaxExt;
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
puzzle.lines().for_each(|battery_bank| { puzzle.lines().for_each(|battery_bank| {

View File

@@ -31,7 +31,7 @@ fn get_n_max(vec: &Vec<u8>, n: usize) -> Vec<u8> {
max max
} }
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
puzzle.lines().for_each(|battery_bank| { puzzle.lines().for_each(|battery_bank| {

View File

@@ -1,5 +1,5 @@
pub fn parse_to_floor(input: String) -> Vec<Vec<u8>> { pub fn parse_to_floor(input: &str) -> Vec<Vec<u8>> {
let mut rows: Vec<Vec<u8>> = Vec::with_capacity(input.len() + 2); let mut rows: Vec<Vec<u8>> = Vec::with_capacity(input.len() + 2);
rows.push(vec![0u8; input.len()]); rows.push(vec![0u8; input.len()]);
rows.append( rows.append(

View File

@@ -19,11 +19,11 @@ mod tests {
#[test] #[test]
fn part04a() { fn part04a() {
assert_eq!(part04a::solve(PUZZLE.to_string()), 13); assert_eq!(part04a::solve(PUZZLE), 13);
} }
#[test] #[test]
fn part04b() { fn part04b() {
assert_eq!(part04b::solve(PUZZLE.to_string()), 43); assert_eq!(part04b::solve(PUZZLE), 43);
} }
} }

View File

@@ -1,5 +1,5 @@
use crate::day04::common::{parse_to_floor, remove_if_possible}; use crate::day04::common::{parse_to_floor, remove_if_possible};
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
remove_if_possible(&mut parse_to_floor(puzzle)).unwrap_or_else(|| 0) remove_if_possible(&mut parse_to_floor(puzzle)).unwrap_or_else(|| 0)
} }

View File

@@ -1,6 +1,6 @@
use crate::day04::common::{parse_to_floor, remove_if_possible}; use crate::day04::common::{parse_to_floor, remove_if_possible};
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
let mut floor = parse_to_floor(puzzle); let mut floor = parse_to_floor(puzzle);

View File

@@ -19,11 +19,11 @@ mod tests {
#[test] #[test]
fn part05a() { fn part05a() {
assert_eq!(part05a::solve(PUZZLE.to_string()), 3); assert_eq!(part05a::solve(PUZZLE), 3);
} }
#[test] #[test]
fn part05b() { fn part05b() {
assert_eq!(part05b::solve(PUZZLE.to_string()), 14); assert_eq!(part05b::solve(PUZZLE), 14);
} }
} }

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let (ranges, values) = puzzle.split_once("\n\n").unwrap(); let (ranges, values) = puzzle.split_once("\n\n").unwrap();
let ranges = ranges let ranges = ranges
.lines() .lines()

View File

@@ -1,6 +1,6 @@
use itertools::Itertools; use itertools::Itertools;
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let (ranges, _) = puzzle.split_once("\n\n").unwrap(); let (ranges, _) = puzzle.split_once("\n\n").unwrap();
let mut last_end = u64::MIN; let mut last_end = u64::MIN;
ranges ranges

View File

@@ -12,11 +12,11 @@ mod tests {
#[test] #[test]
fn part06a() { fn part06a() {
assert_eq!(part06a::solve(PUZZLE.to_string()), 4277556); assert_eq!(part06a::solve(PUZZLE), 4277556);
} }
#[test] #[test]
fn part06b() { fn part06b() {
assert_eq!(part06b::solve(PUZZLE.to_string()), 3263827); assert_eq!(part06b::solve(PUZZLE), 3263827);
} }
} }

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut iters: Vec<_> = puzzle let mut iters: Vec<_> = puzzle
.lines() .lines()
.map(|line| line.split_whitespace()) .map(|line| line.split_whitespace())

View File

@@ -20,7 +20,7 @@ where
} }
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
let lines = puzzle let lines = puzzle

View File

@@ -24,11 +24,11 @@ mod tests {
#[test] #[test]
fn part07a() { fn part07a() {
assert_eq!(part07a::solve(PUZZLE.to_string()), 21); assert_eq!(part07a::solve(PUZZLE), 21);
} }
#[test] #[test]
fn part07b() { fn part07b() {
assert_eq!(part07b::solve(PUZZLE.to_string()), 40); assert_eq!(part07b::solve(PUZZLE), 40);
} }
} }

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution = 0; let mut solution = 0;
let mut lines = puzzle.lines(); let mut lines = puzzle.lines();
let mut source = lines let mut source = lines

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution = 0; let mut solution = 0;
let mut lines = puzzle.lines(); let mut lines = puzzle.lines();
let mut source = lines let mut source = lines

View File

@@ -29,12 +29,12 @@ mod tests {
#[test] #[test]
#[ignore] #[ignore]
fn part08a() { fn part08a() {
assert_eq!(part08a::solve(PUZZLE.to_string()), 40); assert_eq!(part08a::solve(PUZZLE), 40);
} }
#[test] #[test]
#[ignore] #[ignore]
fn part08b() { fn part08b() {
assert_eq!(part08b::solve(PUZZLE.to_string()), 0); assert_eq!(part08b::solve(PUZZLE), 0);
} }
} }

View File

@@ -1,4 +1,4 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
0 // TODO 0 // TODO
} }

View File

@@ -1,4 +1,4 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
0 // TODO 0 // TODO
} }

View File

@@ -16,12 +16,12 @@ mod tests {
#[test] #[test]
fn part09a() { fn part09a() {
assert_eq!(part09a::solve(PUZZLE.to_string()), 50); assert_eq!(part09a::solve(PUZZLE), 50);
} }
#[test] #[test]
#[ignore] #[ignore]
fn part09b() { fn part09b() {
assert_eq!(part09b::solve(PUZZLE.to_string()), 24); assert_eq!(part09b::solve(PUZZLE), 24);
} }
} }

View File

@@ -1,6 +1,6 @@
use std::ops::Add; use std::ops::Add;
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let mut solution: u64 = 0; let mut solution: u64 = 0;
let points = puzzle let points = puzzle

View File

@@ -1,5 +1,5 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
0 // TODO 0 // TODO
} }

View File

@@ -11,12 +11,12 @@ mod tests {
#[test] #[test]
fn part10a() { fn part10a() {
assert_eq!(part10a::solve(PUZZLE.to_string()), 7); assert_eq!(part10a::solve(PUZZLE), 7);
} }
#[test] #[test]
#[ignore] #[ignore]
fn part10b() { fn part10b() {
assert_eq!(part10b::solve(PUZZLE.to_string()), 0); assert_eq!(part10b::solve(PUZZLE), 0);
} }
} }

View File

@@ -33,7 +33,7 @@ fn find_least_combinations<T: BitXor<Output=T> + Eq + Default + Copy>(pre_press:
min_preferring_some(max_pressed, max_unpressed) min_preferring_some(max_pressed, max_unpressed)
} }
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
puzzle puzzle
.lines() .lines()
.map(|line| { .map(|line| {

View File

@@ -1,4 +1,4 @@
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
0 // TODO 0 // TODO
} }

View File

@@ -19,12 +19,12 @@ iii: out";
#[test] #[test]
fn part11a() { fn part11a() {
assert_eq!(part11a::solve(PUZZLE.to_string()), 5); assert_eq!(part11a::solve(PUZZLE), 5);
} }
#[test] #[test]
#[ignore] #[ignore]
fn part11b() { fn part11b() {
assert_eq!(part11b::solve(PUZZLE.to_string()), 0); assert_eq!(part11b::solve(PUZZLE), 0);
} }
} }

View File

@@ -1,7 +1,7 @@
use crate::day11::common::{parse_node_graph}; use crate::day11::common::{parse_node_graph};
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let node_graph = parse_node_graph(&puzzle); let node_graph = parse_node_graph(&puzzle);
node_graph.get(&"you".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()).unwrap().borrow().find_route_to_cont("out".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()) as u64 node_graph.get(&"you".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()).unwrap().borrow().find_route_to_cont("out".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()) as u64

View File

@@ -1,7 +1,7 @@
use crate::day11::common::{parse_node_graph}; use crate::day11::common::{parse_node_graph};
pub fn solve(puzzle: String) -> u64 { pub fn solve(puzzle: &str) -> u64 {
let node_graph = parse_node_graph(&puzzle); let node_graph = parse_node_graph(&puzzle);
node_graph.get(&"you".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()).unwrap().borrow().find_route_to_cont("out".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()) as u64 node_graph.get(&"you".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()).unwrap().borrow().find_route_to_cont("out".chars().map(|c| c as u32).reduce(|a, b| a << 8 | b).unwrap()) as u64

View File

@@ -26,7 +26,7 @@ fn main() {
file.write_all(b"# Advent of Code 2025\n```bash\n") file.write_all(b"# Advent of Code 2025\n```bash\n")
.expect("Cannot write to file"); .expect("Cannot write to file");
let exercises: Vec<(&str, fn(String) -> u64, &str)> = vec![ let exercises: Vec<(&str, fn(&str) -> u64, &str)> = vec![
("day01:A", day01::part01a::solve, "puzzles/input01.txt"), ("day01:A", day01::part01a::solve, "puzzles/input01.txt"),
("day01:B", day01::part01a::solve, "puzzles/input01.txt"), ("day01:B", day01::part01a::solve, "puzzles/input01.txt"),
("day02:A", day02::part02a::solve, "puzzles/input02.txt"), ("day02:A", day02::part02a::solve, "puzzles/input02.txt"),
@@ -58,7 +58,7 @@ fn main() {
let solution = format!( let solution = format!(
"{:7} => {:15} ({:6}us)\n", "{:7} => {:15} ({:6}us)\n",
day, day,
func(file_content), func(&file_content),
day_start.elapsed().as_micros() day_start.elapsed().as_micros()
); );
print!("{}", solution); print!("{}", solution);