1
0

Compare commits

..

No commits in common. "07b0bf755852d84190f13485416256487a057303" and "0d7097dbf84b619dd9657a5f86afba00af2a5928" have entirely different histories.

2 changed files with 10 additions and 35 deletions

View File

@ -1,10 +1,10 @@
use advent_of_code::{prob1, prob2};
use advent_of_code::prob1;
fn main() {
let args: Vec<String> = std::env::args().collect();
let file_path = args
.get(1)
.expect("Please provide an argument on command-line.");
let max = prob2::solve_part1(file_path);
let max = prob1::solve_part2(file_path);
println!("{max}");
}

View File

@ -40,10 +40,7 @@ impl From<char> for Play {
'X' => Play::Rock,
'Y' => Play::Paper,
'Z' => Play::Scissors,
other => panic!(
"Only A, B, C, X, Y or Z letters are available. Had {}",
other
),
_ => panic!("Only A, B, C, X, Y or Z letters are available."),
}
}
}
@ -62,39 +59,17 @@ pub fn round_score(play: char, counter_play: char) -> i32 {
let coup = Play::from(play); // translate to the play
let counter = Play::from(counter_play); // translate to the play
if coup == counter {
let draw: i32 = ResultPlay::Draw.into();
let result: i32 = counter.into();
draw + result
(ResultPlay::Draw as i32) + (counter_play as i32)
} else {
use Play::*;
use ResultPlay::*;
let loss: i32 = Loss.into();
let win: i32 = Win.into();
match (&coup, &counter) {
(Rock, Paper) => {
let result: i32 = counter.into();
win + result
}
(Rock, Scissors) => {
let result: i32 = counter.into();
loss + result
}
(Paper, Rock) => {
let result: i32 = counter.into();
loss + result
}
(Paper, Scissors) => {
let result: i32 = counter.into();
win + result
}
(Scissors, Rock) => {
let result: i32 = counter.into();
win + result
}
(Scissors, Paper) => {
let result: i32 = counter.into();
loss + result
}
(Rock, Paper) => (Win as i32) + (counter as i32),
(Rock, Scissors) => (Loss as i32) + (counter as i32),
(Paper, Rock) => (Loss as i32) + (counter as i32),
(Paper, Scissors) => (Win as i32) + (counter as i32),
(Scissors, Rock) => (Win as i32) + (counter as i32),
(Scissors, Paper) => (Loss as i32) + (counter as i32),
_ => panic!("Case not covered, impossible to reach."),
}
}