Simplify the "find" operation.

This commit is contained in:
2018-11-30 14:13:58 +01:00
parent 2ec8dddb66
commit 48db1dde39

View File

@@ -1,5 +1,4 @@
use common; use common;
use itertools::Itertools;
use std::io::prelude::*; use std::io::prelude::*;
use std::io::BufReader; use std::io::BufReader;
@@ -36,10 +35,7 @@ impl Day21 {
fn find(&self, search: &str) -> usize { fn find(&self, search: &str) -> usize {
let c = search.chars().next().unwrap(); let c = search.chars().next().unwrap();
match self.password.iter().find_position(|&&x| x == c) { self.password.iter().position(|&x| x == c).unwrap()
Some((pos, _)) => pos,
_ => panic!("Char not in password: {}", c)
}
} }
fn reverse_range(&mut self, pos_1: usize, pos_2: usize) fn reverse_range(&mut self, pos_1: usize, pos_2: usize)