mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Simplify the "find" operation.
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user