Function advent_of_code_2021::day_19::try_merge [−][src]
fn try_merge(
beacon_set: &mut HashSet<(isize, isize, isize)>,
scanner: &Vec<(isize, isize, isize)>
) -> Option<(isize, isize, isize)>Expand description
Explode the scanner into its 24 rotations, then for each, pair each up with every element in the fixed beacon set,
and work out the position delta needed to make them match up. If we can find 12 or more point pairs that share the
same delta, that delta gives a translation for the current rotation that has enough overlap to be confident that
is is a match. Take the first rotation (if any) that produces a match. If a match is found, apply that delta to the
current rotation of the scanner data, and merge those points with the existing fixed set. Then return the delta
as that is also the scanner position. Itertools::cartesian_product, Itertools::counts, and
Iterator::find_map respectively do the pairing of scanner points with the existing beacon set, grouping by
delta, and finding the first match (if any) both for the rotations, and delta groups.
