1
0

Added Day 2 Part 1 and it's input

This commit is contained in:
Ishan Jain 2020-12-02 11:46:01 +05:30
parent 743260c752
commit 2d6ec0632d
No known key found for this signature in database
GPG Key ID: F261A0E73038D89D
3 changed files with 1025 additions and 223 deletions

1201
input

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,3 @@
1721
979
366
299
675
1456
1-3 a: abcde
1-3 b: cdefg
2-9 c: ccccccccc

View File

@ -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);
}