day1: part1 initial
This commit is contained in:
1 file changed
+54
+54
@@ -0,0 +1,54 @@
|
|||||||
|
use aoc_runner_derive::aoc;
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
#[aoc(day1, part1)]
|
||||||
|
pub fn part1(input: &str) -> u64 {
|
||||||
|
let ids = input.lines().map(|l| l.parse::<u64>().unwrap()).counts();
|
||||||
|
ids.iter()
|
||||||
|
.sorted_by_key(|(_k, v)| *v)
|
||||||
|
.rev()
|
||||||
|
.take(3)
|
||||||
|
.fold(1, |acc, (k, _v)| acc * k)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[aoc(day1, part2)]
|
||||||
|
pub fn part2(input: &str) -> u64 {
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::day1::*;
|
||||||
|
|
||||||
|
const EXAMPLE: &str = "57
|
||||||
|
57
|
||||||
|
55
|
||||||
|
57
|
||||||
|
76
|
||||||
|
78
|
||||||
|
57
|
||||||
|
45
|
||||||
|
43
|
||||||
|
78
|
||||||
|
43
|
||||||
|
76
|
||||||
|
43
|
||||||
|
78
|
||||||
|
57
|
||||||
|
45
|
||||||
|
57
|
||||||
|
76
|
||||||
|
43
|
||||||
|
43
|
||||||
|
76";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn problem1_example() {
|
||||||
|
assert_eq!(part1(EXAMPLE), 186276);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn problem2_example() {
|
||||||
|
assert_eq!(part2(EXAMPLE), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user