2023 day16/rust: parallelize

This commit is contained in:
Xiretza 2023-12-18 19:11:28 +00:00
parent 603321cfbe
commit c0ed69768b
3 changed files with 6 additions and 2 deletions

View file

@ -8,3 +8,4 @@ edition = "2021"
[dependencies] [dependencies]
aoc = { path = "../../../common/rust" } aoc = { path = "../../../common/rust" }
enum-map = "2.7.3" enum-map = "2.7.3"
rayon = "1.8.0"

View file

@ -4,6 +4,7 @@ use std::{collections::HashMap, io::stdin};
use aoc::vec2::{Direction, Vec2}; use aoc::vec2::{Direction, Vec2};
use enum_map::EnumMap; use enum_map::EnumMap;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Device { enum Device {
@ -168,9 +169,10 @@ fn main() {
(Vec2::new(max_x - 1, y), Direction::Left), (Vec2::new(max_x - 1, y), Direction::Left),
] ]
}); });
let starts: Vec<_> = hor_starts.chain(ver_starts).collect();
let max_energized = hor_starts let max_energized = starts
.chain(ver_starts) .into_par_iter()
.map(|(pos, direction)| energize_fields(PathPosition { pos, direction }, fields.clone())) .map(|(pos, direction)| energize_fields(PathPosition { pos, direction }, fields.clone()))
.max() .max()
.unwrap(); .unwrap();

1
Cargo.lock generated
View file

@ -709,6 +709,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"aoc", "aoc",
"enum-map", "enum-map",
"rayon",
] ]
[[package]] [[package]]