From e6d7480e7d6dbcc3609a020942c7a079a922b60f Mon Sep 17 00:00:00 2001 From: Lennard Brinkhaus Date: Sat, 3 Dec 2022 16:12:17 +0100 Subject: [PATCH] feat: implement day03 --- src/day02.rs | 47 ++- src/day03.rs | 87 +++++ .../question01 => src/input/day01/input01 | 0 .../question01 => src/input/day02/input01 | 0 src/input/day03/input01 | 300 ++++++++++++++++++ src/main.rs | 26 +- src/utils.rs | 7 - 7 files changed, 416 insertions(+), 51 deletions(-) create mode 100644 src/day03.rs rename input/day01/question01 => src/input/day01/input01 (100%) rename input/day02/question01 => src/input/day02/input01 (100%) create mode 100644 src/input/day03/input01 diff --git a/src/day02.rs b/src/day02.rs index 1b816f7..781d8f3 100644 --- a/src/day02.rs +++ b/src/day02.rs @@ -26,7 +26,7 @@ Paper (Y) -> 2 Scissors (Z) -> 3 */ -#[derive(Clone, Copy)] +#[derive(Clone)] enum Move { Rock, Paper, @@ -39,7 +39,7 @@ pub fn execute_task01(content: &str) { let opp_char: char = line.chars().nth(0).unwrap(); let you_char: char = line.chars().nth(2).unwrap(); - calculate_score_from_game(convert_to_move(opp_char), convert_to_move(you_char)) + calculate_score_from_game(&convert_to_move(opp_char), &convert_to_move(you_char)) }).sum(); println!("Day02 - Task01 - Score: {}", score); @@ -54,21 +54,23 @@ pub fn execute_task02(content: &str) { let you_char: char = line.chars().nth(2).unwrap(); let opp_move: Move = convert_to_move(opp_char); - calculate_score_from_game(opp_move, convert_to_conditional_move(opp_move ,you_char)) + calculate_score_from_game(&opp_move, &convert_to_conditional_move(&opp_move ,you_char)) }).sum(); println!("Day02 - Task01 - Score: {}", score); } -fn convert_to_conditional_move(opp: Move, you: char) -> Move { +fn convert_to_conditional_move(opp: &Move, you: char) -> Move { match you { 'X' => match opp { // need to loose Rock => Scissors, Paper => Rock, Scissors => Paper, }, - 'Y' => opp, // need to draw + 'Y' => + + opp.clone(), // need to draw 'Z' => match opp { // need to win Rock => Paper, Paper => Scissors, @@ -87,29 +89,16 @@ fn convert_to_move(c: char) -> Move { } } -fn calculate_score_from_game(opp: Move, you: Move) -> i32 { - match opp { - Rock => { // Opp == Rock - match you { - Rock => 3 + 1, // You Draw with Rock - Paper => 6 + 2, // You Win with Paper - Scissors => 0 + 3, // You Lose with Scissors - } - }, - Paper => { // Opp == Paper - match you { - Rock => 0 + 1, // You Lose with Rock - Paper => 3 + 2, // You Draw with Paper - Scissors => 6 + 3, // You Win with Scissors - } - }, - Scissors => { // Opp == Scissors - match you { - Rock => 6 + 1, // You Win with Rock - Paper => 0 + 2, // You Lose with Paper - Scissors => 3 + 3, // You Draw with Scissors - } - }, - +fn calculate_score_from_game(opp: &Move, you: &Move) -> i32 { + match (opp, you) { + (Rock, Rock) => 3 + 1, // You Draw with Rock + (Rock, Paper) => 6 + 2, // You Win with Paper + (Rock, Scissors) => 0 + 3, // You Lose with Scissors + (Paper, Rock) => 0 + 1, // You Lose with Rock + (Paper, Paper) => 3 + 2, // You Draw with Paper + (Paper, Scissors) => 6 + 3, // You Win with Scissors + (Scissors, Rock) => 6 + 1, // You Win with Rock + (Scissors, Paper) => 0 + 2, // You Lose with Paper + (Scissors, Scissors) => 3 + 3, // You Draw with Scissors } } \ No newline at end of file diff --git a/src/day03.rs b/src/day03.rs new file mode 100644 index 0000000..fa43ea9 --- /dev/null +++ b/src/day03.rs @@ -0,0 +1,87 @@ +use crate::utils; + +pub fn execute_task01(content: &str) { + let vector = utils::convert_to_string_slice(&content); + let rucksack_compartments: Vec<(Vec, Vec)> = vector.iter().map(|line| split_rucksack_in_two_compartments(line)).collect(); + + let duplicates: Vec = rucksack_compartments.iter() + .flat_map(|(vec1, vec2)| vec1.iter() + .copied() + .flat_map(|entry| vec2.iter().copied().map(move |b| (entry, b))) + .filter(|(a, b)| a == b) + .map(|(a, _)| a)) + .collect(); + + let sum: i32 = duplicates.iter().copied().map(|c| convert_char_to_prio(&c)).sum(); + + println!("Day03 - Task01 - Sum of Priorities: {}", sum); +} + +pub fn execute_task02(content: &str) { + let vector = utils::convert_to_string_slice(&content); + let compartments: Vec> = vector.iter().map(|line| split_rucksack_in_items(line)).collect(); + let mut duplicates: Vec = vec![]; + + for i in 0..(compartments.len()/3) { + let first_index = i * 3 + 0; + let second_index = i * 3 + 1; + let third_index = i * 3 + 2; + + let first_vec = compartments.get(first_index).expect("ERR"); + let second_vec = compartments.get(second_index).expect("ERR"); + let third_vec = compartments.get(third_index).expect("ERR"); + + let mut dups: Vec = first_vec.into_iter() + .copied() + .flat_map(|val1| second_vec.into_iter() + .copied() + .flat_map(move |val2| third_vec.into_iter().copied().map(move |val3| (val1, val2, val3)))) + .filter(|(a, b, c)| a == b && b == c) + .map(|(a, _, _)| a) + .collect(); + + duplicates.append(&mut dups) + } + + let sum: i32 = duplicates.iter().copied().map(|c| convert_char_to_prio(&c)).sum(); + + println!("Day03 - Task02 - Sum of Groups of Priorities: {}", sum); +} + +fn split_rucksack_in_two_compartments(rucksack_content: &str) -> (Vec, Vec) { + let first_compartment: &str = &rucksack_content[..rucksack_content.len()/2]; + let second_compartment: &str = &rucksack_content[rucksack_content.len()/2..]; + + let mut first_compartment_vec: Vec = first_compartment.chars().map(|c| c).collect(); + let mut second_compartment_vec: Vec = second_compartment.chars().map(|c| c).collect(); + + first_compartment_vec.sort(); + first_compartment_vec.dedup(); + second_compartment_vec.sort(); + second_compartment_vec.dedup(); + + return ( first_compartment_vec, second_compartment_vec); +} + +fn split_rucksack_in_items(rucksack_content: &str) -> Vec { + let mut vec: Vec = rucksack_content.chars().map(|c| c).collect(); + + vec.sort(); + vec.dedup(); + + return vec; +} + +pub fn convert_char_to_prio(c: &char) -> i32 { + let c_code = c.clone() as u8; + + if 65 <= c_code && c_code < 91 { + return (c_code - 64 + 26) as i32; + } + + if 97 <= c_code && c_code < 123 { + return (c_code - 96) as i32; + } + + panic!("never should called"); +} \ No newline at end of file diff --git a/input/day01/question01 b/src/input/day01/input01 similarity index 100% rename from input/day01/question01 rename to src/input/day01/input01 diff --git a/input/day02/question01 b/src/input/day02/input01 similarity index 100% rename from input/day02/question01 rename to src/input/day02/input01 diff --git a/src/input/day03/input01 b/src/input/day03/input01 new file mode 100644 index 0000000..556acc3 --- /dev/null +++ b/src/input/day03/input01 @@ -0,0 +1,300 @@ +jLnFTjhwFTLFDGDDvLgvDssBJBbVRNZJPPJBGzBNRVJNRB +QWmffSmMZCfWrmHlCflQWfSNBpVBNbPSbbJNppcVVzzpcp +lflrqrWMmfdMlrtWWmZgDjsqwFwhFDsngnvhqs +CNBGwsWVsdWDNCCVvfPLfQfgZHPBvpgf +qhJqJlmcFnhJclllPgZjvpHpvfZpPbLn +lpMJJhhcSMDMMwws +jphtLMfVpjJRjJscMJptssnrwdNwQrNbwNzQTbcNrwQT +gSPPSqGGGrdLrNQGrr +PvWPDvWWCSSBBZPjLVDfhjsLLsDhtR +hlLwDGLNnTrbNdtbdb +ZfsvJbsJTrsttHTR +vjPQJPFcmZjVFZFvbbVcJZJPBBhLMnDBznnGMDLMwBhlmBBl +JdTJFtwHjJTzPMqPccqzjB +rggffSCvNBCbWBWt +ZsSpnnRpLStrZpTDwTVwGTJHDLdH +sZqswsrcRpCrsCsrrbtpbpDlttlFbbpGtj +LhNgNvNNhTQMhQMWhvvhfWhllbGGPbPtlPmFlDbjHHdlmg +ffNBNMhDvQDhvzhBhNTBnSzzrZCZnrsVCSwcnrCC +hHGhjLjwtFGwGhhhhtwjtlhrDBQrRBHczRcMvsBcRrDDMH +TTfbZdZbPbVCmCdmnZmCVdfrJBczMrrznvBvQBzzzcBscn +fdbPZTVVfSdmbfdvjjSGljhhtNGGhL +fMrGQbPrbnfljjzVLQzNCzVv +WcDqlSpctSJNzSFJLCzN +hBBWcHtWgWDmZlwwrsPrRTRTMrmn +ZJTVdgpzPpLVVwZgPzTPLwgWdhcWhSQCbcSbBtSWdSWchb +qnDGnNjqDqNlqsCSWhMtlMltWSQB +NnNrFQGjDRgLrgrpPr +nCrhsmVrlrzsTvsnVvmTTlpvPJPWWMPJWWPCJMPNPgPJMj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+qDlqVthTztSSpSlqtpTTzLvRRnnCvRCPLBQGDBdDGD +HlmlJgRBBpJLpPBHnlLJsrgJDMttvSdddcMSStWjjWtcSzjs +qfTbNPTVGhGFCVGTwZfNZNNVWvjSczcjStMMcdSczzczvbcW +GZVqffQTwNQTmPRlggHLprHQ +BjsWschcTjjWclQTSnZFrjtFtbzZfqntzF +qggNGMHgvHMRZMtznbrftMCn +qvHdqpwgJTsVccwscT +FJwNPHJmPHTJHglTFwgmwqtShBqDmDBzzBzWhCDWqQ +fpsjNsMVLVjDCCSzBtjztt +sLrdfbsMcbMRZZZbbsfrsrNgGNglRwllRnJnwFvnFHnG +lWWVTJlJCTTzDdWzqdtFFt +PvPvrhbjhgSjvJQSnQRbjZDZFFHMtGGqFtRMGZFtGH +rhPrSgfvJPfmwsTpLcsV \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 74a6628..f8519f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,19 @@ mod utils; mod day01; mod day02; +mod day03; + +const CONTENT01: &'static str = include_str!("input/day01/input01"); +const CONTENT02: &'static str = include_str!("input/day02/input01"); +const CONTENT03: &'static str = include_str!("input/day03/input01"); fn main() { - let path01 = "input/day01/question01"; - let content01: String = match utils::load_file_as_string(path01) { - Ok(content) => content, - Err(error) => panic!("Problem opening the file: {:?}", error), - }; + day01::execute_task01(&CONTENT01); + day01::execute_task02(&CONTENT01); - let path02 = "input/day02/question01"; - let content02: String = match utils::load_file_as_string(path02) { - Ok(content) => content, - Err(error) => panic!("Problem opening the file: {:?}", error), - }; + day02::execute_task01(&CONTENT02); + day02::execute_task02(&CONTENT02); - day01::execute_task01(&content01); - day01::execute_task02(&content01); - - day02::execute_task01(&content02); - day02::execute_task02(&content02); + day03::execute_task01(&CONTENT03); + day03::execute_task02(&CONTENT03) } diff --git a/src/utils.rs b/src/utils.rs index ef8a213..0dedcbf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,10 +1,3 @@ -use std::fs; -use std::error::Error; - -pub fn load_file_as_string(path: &str) -> Result> { - let content = fs::read_to_string(path)?; - Ok(content) -} pub fn convert_to_string_slice(content: &str) -> Vec<&str> { content.lines().collect()