1
0
Fork 0

Added Day 2 Part 2

This commit is contained in:
Ishan Jain 2020-12-02 11:46:19 +05:30
parent 2d6ec0632d
commit a43f38687b
No known key found for this signature in database
GPG Key ID: F261A0E73038D89D
1 changed files with 8 additions and 7 deletions

View File

@ -16,15 +16,16 @@ fn main() {
let mut policy = policy.split_whitespace(); let mut policy = policy.split_whitespace();
let limits = policy.next().unwrap(); let limits = policy.next().unwrap();
let mut limits = limits.split('-'); let mut positions = limits.split('-');
let lowerlimit = limits.next().unwrap().parse::<usize>().unwrap(); let lpos = positions.next().unwrap().parse::<usize>().unwrap();
let upperlimit = limits.next().unwrap().parse::<usize>().unwrap(); let rpos = positions.next().unwrap().parse::<usize>().unwrap();
(lowerlimit, upperlimit, chars, pwd) (lpos, rpos, chars, pwd)
}) })
.filter(|(lowerlimit, upperlimit, chars, pwd)| { .filter(|&(lpos, rpos, c, pwd)| {
let count = &pwd.chars().filter(|x| x == chars).count(); let pwd: Vec<char> = pwd.chars().collect();
count >= lowerlimit && count <= upperlimit
(pwd[lpos - 1] == c || pwd[rpos - 1] == c) && (pwd[lpos - 1] != pwd[rpos - 1])
}) })
.count(); .count();