day1: part2
This commit is contained in:
1 file changed
+6
-2
+6
-2
@@ -13,7 +13,11 @@ pub fn part1(input: &str) -> u64 {
|
|||||||
|
|
||||||
#[aoc(day1, part2)]
|
#[aoc(day1, part2)]
|
||||||
pub fn part2(input: &str) -> u64 {
|
pub fn part2(input: &str) -> u64 {
|
||||||
0
|
let ids = input.lines().map(|l| l.parse::<u64>().unwrap()).counts();
|
||||||
|
ids.iter()
|
||||||
|
.sorted_by_key(|(_k, v)| *v)
|
||||||
|
.take(3)
|
||||||
|
.fold(1, |acc, (k, _v)| acc * k)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -49,6 +53,6 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn problem2_example() {
|
fn problem2_example() {
|
||||||
assert_eq!(part2(EXAMPLE), 0);
|
assert_eq!(part2(EXAMPLE), 193050);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user