File: aoc-2020-10.rs

package info (click to toggle)
rust-pathfinding 4.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,024 kB
  • sloc: sh: 19; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 538 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use pathfinding::directed::count_paths::count_paths;

#[test]
fn part2() {
    let mut adapters: Vec<i32> = include_str!("aoc-2020-10.txt")
        .lines()
        .map(|x| x.parse().unwrap())
        .collect();

    adapters.sort_unstable();

    let &last = adapters.last().unwrap();

    let n = count_paths(
        0,
        |&x| {
            adapters
                .iter()
                .filter(move |&&y| y > x && y <= x + 3)
                .copied()
        },
        |&x| x == last,
    );

    assert_eq!(n, 19208);
}