From c2e3422544c079c426d16a93de89e19b0ff1aaf5 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Wed, 18 Dec 2024 23:07:13 -0800 Subject: [PATCH] day19: rayon - ez mode parallelization, speed * 6 --- src/day19.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/day19.rs b/src/day19.rs index 78f7cc0..781e3a4 100644 --- a/src/day19.rs +++ b/src/day19.rs @@ -1,5 +1,6 @@ use aoc_runner_derive::aoc; use itertools::Itertools; +use rayon::iter::{IntoParallelIterator, ParallelIterator}; use rustc_hash::FxHashMap; use std::fmt::{Display, Write}; @@ -39,7 +40,7 @@ impl Display for Stripe { } } -#[derive(Debug)] +#[derive(Debug, Clone)] struct Design { stripes: Vec, } @@ -118,14 +119,16 @@ impl Onsen { } fn count_possible(&self) -> i64 { self.designs - .iter() + .clone() + .into_par_iter() .map(|d| self.possible(&d.stripes)) .filter(|p| *p) .count() as i64 } fn count_ways(&self) -> i64 { self.designs - .iter() + .clone() + .into_par_iter() .map(|d| self.ways(&d.stripes, FxHashMap::default()).1) .sum::() }