[rs] Optimize 2022_16
This commit is contained in:
parent
efaaef4e6a
commit
f90e633971
1 changed files with 14 additions and 12 deletions
|
|
@ -243,18 +243,9 @@ fn solve_part_2(names: &HashMap<&str, usize>, valves: &[Valve], powerset: &[Open
|
||||||
let mut variations = vec![];
|
let mut variations = vec![];
|
||||||
for (own_id, own_valve) in valves.iter().enumerate() {
|
for (own_id, own_valve) in valves.iter().enumerate() {
|
||||||
for (el_id, el_valve) in valves.iter().enumerate() {
|
for (el_id, el_valve) in valves.iter().enumerate() {
|
||||||
for open in powerset {
|
variations.push((own_id, own_valve, el_id, el_valve));
|
||||||
variations.push((own_id, own_valve, el_id, el_valve, open));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Just to check whether the variations are in the correct order because I'm
|
|
||||||
// zipping them to curr.elems later.
|
|
||||||
for (i, (own_id, _, el_id, _, open)) in variations.iter().enumerate() {
|
|
||||||
let id = curr.powers * (curr.valves * own_id + el_id) + open.0 as usize;
|
|
||||||
assert_eq!(i, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
for minute in 1..=26 {
|
for minute in 1..=26 {
|
||||||
eprintln!("Minute {minute}");
|
eprintln!("Minute {minute}");
|
||||||
|
|
@ -263,9 +254,20 @@ fn solve_part_2(names: &HashMap<&str, usize>, valves: &[Valve], powerset: &[Open
|
||||||
|
|
||||||
curr.elems
|
curr.elems
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
|
.chunks(powerset.len())
|
||||||
.zip(variations.par_iter())
|
.zip(variations.par_iter())
|
||||||
.for_each(|(score, (own_id, own_valve, el_id, el_valve, open))| {
|
.for_each(|(scores, (own_id, own_valve, el_id, el_valve))| {
|
||||||
*score = part_2_score(minute, &prev, *own_id, own_valve, *el_id, el_valve, **open);
|
for (i, score) in scores.into_iter().enumerate() {
|
||||||
|
*score = part_2_score(
|
||||||
|
minute,
|
||||||
|
&prev,
|
||||||
|
*own_id,
|
||||||
|
own_valve,
|
||||||
|
*el_id,
|
||||||
|
el_valve,
|
||||||
|
OpenSet(i as u64),
|
||||||
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue