Added Day 2 Part 1 and it's input
This commit is contained in:
parent
743260c752
commit
2d6ec0632d
|
@ -1,6 +1,3 @@
|
|||
1721
|
||||
979
|
||||
366
|
||||
299
|
||||
675
|
||||
1456
|
||||
1-3 a: abcde
|
||||
1-3 b: cdefg
|
||||
2-9 c: ccccccccc
|
||||
|
|
38
src/main.rs
38
src/main.rs
|
@ -1,28 +1,32 @@
|
|||
use std::collections::HashSet;
|
||||
use std::io::{stdin, Read};
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
stdin().read_to_string(&mut input).unwrap();
|
||||
|
||||
let numbers: HashSet<u64> = input
|
||||
let count = input
|
||||
.split('\n')
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|x| x.parse::<u64>().unwrap())
|
||||
.filter(|&x| x <= 2020)
|
||||
.collect();
|
||||
.map(|x| {
|
||||
let mut x = x.split(':');
|
||||
let policy = x.next().unwrap().trim();
|
||||
let pwd = x.next().unwrap().trim();
|
||||
let chars = policy.chars().last().unwrap();
|
||||
|
||||
'outer: for (i, &num1) in numbers.iter().enumerate() {
|
||||
let diff = 2020 - num1;
|
||||
let mut policy = policy.split_whitespace();
|
||||
let limits = policy.next().unwrap();
|
||||
|
||||
for (j, &num2) in numbers.iter().enumerate() {
|
||||
if i == j {
|
||||
continue;
|
||||
}
|
||||
if numbers.contains(&(diff - num2)) {
|
||||
println!("{}", num1 * num2 * (diff - num2));
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut limits = limits.split('-');
|
||||
let lowerlimit = limits.next().unwrap().parse::<usize>().unwrap();
|
||||
let upperlimit = limits.next().unwrap().parse::<usize>().unwrap();
|
||||
|
||||
(lowerlimit, upperlimit, chars, pwd)
|
||||
})
|
||||
.filter(|(lowerlimit, upperlimit, chars, pwd)| {
|
||||
let count = &pwd.chars().filter(|x| x == chars).count();
|
||||
count >= lowerlimit && count <= upperlimit
|
||||
})
|
||||
.count();
|
||||
|
||||
println!("{}", count);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user