From d5828a5b0b2cd5068b3d46e57e38a36f2273a0a6 Mon Sep 17 00:00:00 2001 From: "RingOfStorms (Joshua Bell)" Date: Tue, 5 Dec 2023 04:41:07 -0600 Subject: [PATCH] prepare day 6 --- src/bin/day5.rs | 5 +++-- src/utils/aoc.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/day5.rs b/src/bin/day5.rs index aab9255..9033983 100644 --- a/src/bin/day5.rs +++ b/src/bin/day5.rs @@ -146,7 +146,6 @@ fn part1(input: String) -> Result { .split_whitespace() .map(|s| s.parse::().expect("failed to parse seed as number")) .map(|source| almanac.map_source(source, "seed", "location")) - .par_bridge() .min() .ok_or("failed to get min location")?; let algo_time = start.elapsed(); @@ -177,6 +176,7 @@ fn part2(input: String) -> Result { .map(|s| s.parse::().expect("failed to parse seed as number")) .tuples() .flat_map(|(start, length)| start..start + length) + // Squeeze with rayon for brute force approach .par_bridge() .map(|source| almanac.map_source(source, "seed", "location")) .min() @@ -184,12 +184,13 @@ fn part2(input: String) -> Result { let algo_time = start.elapsed(); // output - println!("Day 5, part 1: {answer}"); + println!("Day 5, part 2: {answer}"); println!("\tparse: {parsed_time:?}"); println!("\talgo: {algo_time:?}"); Ok(answer) } +// TODO come back and revise for a faster solution #[tokio::main] async fn main() -> Result<()> { let input = utils::aoc::get_puzzle_input(5).await?; diff --git a/src/utils/aoc.rs b/src/utils/aoc.rs index fd06dbe..b2fdad1 100644 --- a/src/utils/aoc.rs +++ b/src/utils/aoc.rs @@ -11,7 +11,7 @@ use std::path::PathBuf; static AOC_PUZZLE_INPUT_CACHE: &str = "aoc_puzzle_cache"; -pub async fn get_puzzle_input(day: i8) -> Result { +pub async fn get_puzzle_input(day: u8) -> Result { let file_name = format!("day_{}", day); let cache_path = PathBuf::from(AOC_PUZZLE_INPUT_CACHE).join(file_name); if cache_path.exists() {