RustFmt on all the things

This commit is contained in:
Eryn Wells 2022-12-05 20:57:32 -08:00
parent 7bee28bdf6
commit 2251854f9c
7 changed files with 138 additions and 95 deletions

View file

@ -13,7 +13,10 @@ fn priority_items_in_knapsack(knapsack: &str) -> Vec<char> {
let left_compartment_set: HashSet<char> = HashSet::from_iter(left_compartment.chars());
let right_compartment_set: HashSet<char> = HashSet::from_iter(right_compartment.chars());
left_compartment_set.intersection(&right_compartment_set).map(|c| *c).collect()
left_compartment_set
.intersection(&right_compartment_set)
.map(|c| *c)
.collect()
}
fn badge_for_group(group: (&str, &str, &str)) -> Vec<char> {
@ -21,14 +24,8 @@ fn badge_for_group(group: (&str, &str, &str)) -> Vec<char> {
let b_set: HashSet<char> = HashSet::from_iter(group.1.chars());
let c_set: HashSet<char> = HashSet::from_iter(group.2.chars());
let ab_intersection: HashSet<char> = a_set
.intersection(&b_set)
.map(|c| *c)
.collect();
ab_intersection
.intersection(&c_set)
.map(|c| *c)
.collect()
let ab_intersection: HashSet<char> = a_set.intersection(&b_set).map(|c| *c).collect();
ab_intersection.intersection(&c_set).map(|c| *c).collect()
}
pub fn main(filename: &str) -> Result<()> {
@ -52,33 +49,34 @@ pub fn main(filename: &str) -> Result<()> {
const LOWERCASE_A_SCORE: u32 = 'a' as u32;
const UPPERCASE_A_SCORE: u32 = 'A' as u32;
let sum_of_scored_priority_letters: u32 =
priority_letters
.iter()
.map(|c| -> u32 {
let char_value: u32 = (*c).into();
if c.is_lowercase() {
char_value - LOWERCASE_A_SCORE + 1
} else {
char_value - UPPERCASE_A_SCORE + 27
}
})
.sum();
let sum_of_scored_priority_letters: u32 = priority_letters
.iter()
.map(|c| -> u32 {
let char_value: u32 = (*c).into();
if c.is_lowercase() {
char_value - LOWERCASE_A_SCORE + 1
} else {
char_value - UPPERCASE_A_SCORE + 27
}
})
.sum();
println!("Part 1: sum of scores of all priority items: {}", sum_of_scored_priority_letters);
println!(
"Part 1: sum of scores of all priority items: {}",
sum_of_scored_priority_letters
);
let sum_of_badges: u32 =
badges
.iter()
.map(|c| -> u32 {
let char_value: u32 = (*c).into();
if c.is_lowercase() {
char_value - LOWERCASE_A_SCORE + 1
} else {
char_value - UPPERCASE_A_SCORE + 27
}
})
.sum();
let sum_of_badges: u32 = badges
.iter()
.map(|c| -> u32 {
let char_value: u32 = (*c).into();
if c.is_lowercase() {
char_value - LOWERCASE_A_SCORE + 1
} else {
char_value - UPPERCASE_A_SCORE + 27
}
})
.sum();
println!("Part 2: sum of badges: {}", sum_of_badges);