feat: implement day03

This commit is contained in:
Lennard Brinkhaus 2022-12-03 16:12:17 +01:00
parent 1802867d05
commit e6d7480e7d
Signed by: lennard.brinkhaus
GPG Key ID: 286421EC53998B22
7 changed files with 416 additions and 51 deletions

View File

@ -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
}
}

87
src/day03.rs Normal file
View File

@ -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<char>, Vec<char>)> = vector.iter().map(|line| split_rucksack_in_two_compartments(line)).collect();
let duplicates: Vec<char> = 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<Vec<char>> = vector.iter().map(|line| split_rucksack_in_items(line)).collect();
let mut duplicates: Vec<char> = 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<char> = 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<char>, Vec<char>) {
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<char> = first_compartment.chars().map(|c| c).collect();
let mut second_compartment_vec: Vec<char> = 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<char> {
let mut vec: Vec<char> = 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");
}

300
src/input/day03/input01 Normal file
View File

@ -0,0 +1,300 @@
jLnFTjhwFTLFDGDDvLgvDssBJBbVRNZJPPJBGzBNRVJNRB
QWmffSmMZCfWrmHlCflQWfSNBpVBNbPSbbJNppcVVzzpcp
lflrqrWMmfdMlrtWWmZgDjsqwFwhFDsngnvhqs
CNBGwsWVsdWDNCCVvfPLfQfgZHPBvpgf
qhJqJlmcFnhJclllPgZjvpHpvfZpPbLn
lpMJJhhcSMDMMwws
jphtLMfVpjJRjJscMJptssnrwdNwQrNbwNzQTbcNrwQT
gSPPSqGGGrdLrNQGrr
PvWPDvWWCSSBBZPjLVDfhjsLLsDhtR
hlLwDGLNnTrbNdtbdb
ZfsvJbsJTrsttHTR
vjPQJPFcmZjVFZFvbbVcJZJPBBhLMnDBznnGMDLMw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
WDMDtDNDctVFJstJ
rFDbGjrGbpBBbrCbrwpvvZQZZhgTLVVVVLgThCTggg
NlfHpttqzltMzRSMSdWRNSfSTTmqgcLgQVcQTcmgQgmZVPVZ
HWSWpMHNpNWlpNMsMzWGGwwBvvwBnwBvsnnvnB
mZVVHmmRZlvdjvNpHh
DFBnFDtnFbBMrQbBMvFLvgtjjNpcLpJdNzJJdhWNpJNWcN
QTsbrQggBsvsgVTwRVGZCfGZfR
RGNGlGTWJnJlMcRMGqvSmnDtvDDvtLSLvr
HfsFhPPdVshfbggDVmzcvSwvStVzDq
BPPfCgCFfcBbPbHbBHZPFsbBpMGlClRNJRlQTjQWjWpTTlGT
HQNqQbbRQHbZPZQPqbZTvWFWmCjvFRvRTSrRrr
lBpBpzLLdBwsLwLLWNggzCFTCmFgWmrF
VwsswGVBfJfccLBcsJGNdpJHZZqnhtqqnhPHDZHVtPQMZn
LMHnHnPMnFdJFNFJjZvrJF
wlTlslptlwtzcvTqvTsVSWWrbJfmJZNZJjcNWfNJmf
qDlqVthTztSSpSlqtpTTzLvRRnnCvRCPLBQGDBdDGD
HlmlJgRBBpJLpPBHnlLJsrgJDMttvSdddcMSStWjjWtcSzjs
qfTbNPTVGhGFCVGTwZfNZNNVWvjSczcjStMMcdSczzczvbcW
GZVqffQTwNQTmPRlggHLprHQ
BjsWschcTjjWclQTSnZFrjtFtbzZfqntzF
qggNGMHgvHMRZMtznbrftMCn
qvHdqpwgJTsVccwscT
FJwNPHJmPHTJHglTFwgmwqtShBqDmDBzzBzWhCDWqQ
fpsjNsMVLVjDCCSzBtjztt
sLrdfbsMcbMRZZZbbsfrsrNgGNglRwllRnJnwFvnFHnG
lWWVTJlJCTTzDdWzqdtFFt
PvPvrhbjhgSjvJQSnQRbjZDZFFHMtGGqFtRMGZFtGH
rhPrSgfvJPfmwsTpLcsV

View File

@ -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)
}

View File

@ -1,10 +1,3 @@
use std::fs;
use std::error::Error;
pub fn load_file_as_string(path: &str) -> Result<String, Box<dyn Error>> {
let content = fs::read_to_string(path)?;
Ok(content)
}
pub fn convert_to_string_slice(content: &str) -> Vec<&str> {
content.lines().collect()