Some formatting cleanups.
This commit is contained in:
@@ -38,7 +38,11 @@ impl FromStr for PasswordData {
|
|||||||
|
|
||||||
impl PasswordData {
|
impl PasswordData {
|
||||||
fn is_valid_interpretation1(&self) -> bool {
|
fn is_valid_interpretation1(&self) -> bool {
|
||||||
let count = self.password.chars().filter(|x| *x == self.character).count();
|
let count = self
|
||||||
|
.password
|
||||||
|
.chars()
|
||||||
|
.filter(|x| *x == self.character)
|
||||||
|
.count();
|
||||||
(count >= self.first_number) && (count <= self.second_number)
|
(count >= self.first_number) && (count <= self.second_number)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +64,6 @@ impl PasswordData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn real_main() -> Result<(), TopLevelError> {
|
fn real_main() -> Result<(), TopLevelError> {
|
||||||
let mut good_items_interpretation1 = 0u64;
|
let mut good_items_interpretation1 = 0u64;
|
||||||
let mut good_items_interpretation2 = 0u64;
|
let mut good_items_interpretation2 = 0u64;
|
||||||
@@ -83,8 +86,14 @@ fn real_main() -> Result<(), TopLevelError> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("# of good passwords, according to interpretation #1: {}", good_items_interpretation1);
|
println!(
|
||||||
println!("# of good passwords, according to interpretation #2: {}", good_items_interpretation2);
|
"# of good passwords, according to interpretation #1: {}",
|
||||||
|
good_items_interpretation1
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"# of good passwords, according to interpretation #2: {}",
|
||||||
|
good_items_interpretation2
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,14 +35,16 @@ convert_error!(io::Error, TopLevelError, IOError);
|
|||||||
|
|
||||||
pub enum PasswordParseError {
|
pub enum PasswordParseError {
|
||||||
StringToIntError(ParseIntError),
|
StringToIntError(ParseIntError),
|
||||||
NomError(nom::Err<()>)
|
NomError(nom::Err<()>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for PasswordParseError {
|
impl fmt::Display for PasswordParseError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
PasswordParseError::NomError(e) => write!(f, "Parse error: {}", e),
|
PasswordParseError::NomError(e) => write!(f, "Parse error: {}", e),
|
||||||
PasswordParseError::StringToIntError(e) => write!(f, "Error converting string to integer: {}", e),
|
PasswordParseError::StringToIntError(e) => {
|
||||||
|
write!(f, "Error converting string to integer: {}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user