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