Formatting wibbles before starting day 5.
This commit is contained in:
@@ -24,7 +24,7 @@ macro_rules! valid_range {
|
|||||||
Ok(x) if x < $low || x > $high => return false,
|
Ok(x) if x < $low || x > $high => return false,
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Passport {
|
impl Passport {
|
||||||
@@ -66,13 +66,13 @@ impl Passport {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_basically_valid(&self) -> bool {
|
fn is_basically_valid(&self) -> bool {
|
||||||
self.birth_year.is_some() &&
|
self.birth_year.is_some()
|
||||||
self.issue_year.is_some() &&
|
&& self.issue_year.is_some()
|
||||||
self.expiration_year.is_some() &&
|
&& self.expiration_year.is_some()
|
||||||
self.height.is_some() &&
|
&& self.height.is_some()
|
||||||
self.hair_color.is_some() &&
|
&& self.hair_color.is_some()
|
||||||
self.eye_color.is_some() &&
|
&& self.eye_color.is_some()
|
||||||
self.passport_id.is_some()
|
&& self.passport_id.is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_really_valid(&self) -> bool {
|
fn is_really_valid(&self) -> bool {
|
||||||
@@ -100,7 +100,6 @@ impl Passport {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +117,7 @@ impl Passport {
|
|||||||
// check the eye color
|
// check the eye color
|
||||||
match self.eye_color {
|
match self.eye_color {
|
||||||
None => return false,
|
None => return false,
|
||||||
Some(ref x) if VALID_EYE_COLORS.contains(&x.as_str()) => {},
|
Some(ref x) if VALID_EYE_COLORS.contains(&x.as_str()) => {}
|
||||||
Some(_) => return false,
|
Some(_) => return false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,19 +145,28 @@ fn real_main() -> Result<(), TopLevelError> {
|
|||||||
let mut current_passport = Passport::new();
|
let mut current_passport = Passport::new();
|
||||||
|
|
||||||
for line in contents.lines() {
|
for line in contents.lines() {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
passports.push(current_passport);
|
passports.push(current_passport);
|
||||||
current_passport = Passport::new();
|
current_passport = Passport::new();
|
||||||
} else {
|
} else {
|
||||||
current_passport.injest_data(line)?;
|
current_passport.injest_data(line)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
passports.push(current_passport);
|
passports.push(current_passport);
|
||||||
}
|
}
|
||||||
|
|
||||||
let valid_passports: Vec<&Passport> = passports.iter().filter(|x| x.is_basically_valid()).collect();
|
let valid_passports: Vec<&Passport> = passports
|
||||||
println!("There are {} *basically* valid passports.", valid_passports.len());
|
.iter()
|
||||||
println!(" ... {} are really valid", passports.iter().filter(|x| x.is_really_valid()).count());
|
.filter(|x| x.is_basically_valid())
|
||||||
|
.collect();
|
||||||
|
println!(
|
||||||
|
"There are {} *basically* valid passports.",
|
||||||
|
valid_passports.len()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
" ... {} are really valid",
|
||||||
|
passports.iter().filter(|x| x.is_really_valid()).count()
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,9 @@ pub enum PassportParseError {
|
|||||||
impl fmt::Display for PassportParseError {
|
impl fmt::Display for PassportParseError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
PassportParseError::InvalidChunk(s) => write!(f, "Invalid chunk in passport line: {}", s),
|
PassportParseError::InvalidChunk(s) => {
|
||||||
|
write!(f, "Invalid chunk in passport line: {}", s)
|
||||||
|
}
|
||||||
PassportParseError::InvalidField(s) => write!(f, "Invalid field in passport: {}", s),
|
PassportParseError::InvalidField(s) => write!(f, "Invalid field in passport: {}", s),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user