mirror of
https://github.com/danbulant/adventOfCode
synced 2026-06-19 22:31:03 +00:00
use closure instead of vector
This commit is contained in:
parent
f831229145
commit
0341907983
1 changed files with 17 additions and 20 deletions
|
|
@ -2,7 +2,7 @@ use std::{fs::File, io::{BufReader, BufRead, Write}, ops::Add, fmt::Debug, hash:
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
part1();
|
part1();
|
||||||
// part2();
|
part2();
|
||||||
// println!("test");
|
// println!("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,28 +248,25 @@ fn get_count(max_point: Point, rows: &Vec<Vec<MapPoint>>, columns: &Vec<Vec<MapP
|
||||||
},
|
},
|
||||||
Some(mappoint) => {
|
Some(mappoint) => {
|
||||||
mark(vec, beam.point, (if vec_is_vertical { mappoint.point.y } else { mappoint.point.x } ) + (if vec.is_positive() { 1 } else { 0 }), &mut energized);
|
mark(vec, beam.point, (if vec_is_vertical { mappoint.point.y } else { mappoint.point.x } ) + (if vec.is_positive() { 1 } else { 0 }), &mut energized);
|
||||||
let mut vecs = Vec::with_capacity(2);
|
let point = mappoint.point;
|
||||||
|
let mut try_add = |v: Vector| if !v.will_go_oob(point, max_point) {
|
||||||
|
let new_point = point + v;
|
||||||
|
let beam = Beam {
|
||||||
|
point: new_point,
|
||||||
|
vector: v
|
||||||
|
};
|
||||||
|
let bnum = beam.to_nums();
|
||||||
|
if beams_set_vec[bnum] == false {
|
||||||
|
beams_set_vec[bnum] = true;
|
||||||
|
beams.push(beam);
|
||||||
|
}
|
||||||
|
};
|
||||||
if mappoint.mirror == Type::SplitHorizontal || mappoint.mirror == Type::SplitVertical {
|
if mappoint.mirror == Type::SplitHorizontal || mappoint.mirror == Type::SplitVertical {
|
||||||
let (v1, v2) = vectors_from_split(mappoint.mirror);
|
let (v1, v2) = vectors_from_split(mappoint.mirror);
|
||||||
vecs.push(v1);
|
try_add(v1);
|
||||||
vecs.push(v2);
|
try_add(v2);
|
||||||
} else {
|
} else {
|
||||||
vecs.push(vec.map_by_mirror(mappoint.mirror));
|
try_add(vec.map_by_mirror(mappoint.mirror));
|
||||||
}
|
|
||||||
let point = mappoint.point;
|
|
||||||
for v in vecs {
|
|
||||||
if !v.will_go_oob(point, max_point) {
|
|
||||||
let new_point = point + v;
|
|
||||||
let beam = Beam {
|
|
||||||
point: new_point,
|
|
||||||
vector: v
|
|
||||||
};
|
|
||||||
let bnum = beam.to_nums();
|
|
||||||
if beams_set_vec[bnum] == false {
|
|
||||||
beams_set_vec[bnum] = true;
|
|
||||||
beams.push(beam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue