-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
46 lines (40 loc) · 1.47 KB
/
main.rs
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#![feature(iter_collect_into)]
mod combinator;
use rayon::prelude::*;
use combinator::*;
fn main() {
let run_part = |arr: &Vec<(String,Vec<usize>)>| -> usize {
arr.par_iter()
.map(|(broken, record)| {
Combinator::default().get_combinations(broken, record)
})
.sum::<usize>()
};
let input = std::fs::read_to_string("src/bin/day12/input.txt").expect("Ops");
let arr = parse(input.as_str(),1);
let t = std::time::Instant::now();
println!("Part 1 Sum {:?} - {:?}", run_part(&arr), t.elapsed());
let arr = parse(input.as_str(),5);
let t = std::time::Instant::now();
println!("Part 2 Sum {:?} - {:?}", run_part(&arr), t.elapsed());
}
fn parse(input:&str, repetitions: usize) -> Vec<(String, Vec<usize>)> {
input.lines()
.map(|line| {
let mut split = line.split_ascii_whitespace();
let mut broken_rec = split.next()
.map(|s|{ let mut t = String::from(s); if repetitions > 1 { t.push('?') } t })
.unwrap()
.repeat(repetitions);
if repetitions > 1 { broken_rec.pop(); }
let rec = split.next()
.map(|s|{
s.split(',')
.map(|n| n.parse::<usize>().expect("Ops!")).collect::<Vec<_>>()
})
.unwrap_or_default()
.repeat(repetitions);
( broken_rec, rec )
})
.collect::<Vec<_>>()
}