Function advent_of_code_2021::day_7::find_distance_to_median[−][src]

fn find_distance_to_median(positions: &Vec<usize>) -> usize
Expand description

First find the median by sorting the list and taking the value at the midpoint. As discussed in the summary, either midpoint is fine in the case of an even length list, so just use the default rounding. Secondly iterate through the list to total the distance to the median and sum those values.