Compare commits
No commits in common. "0d7097dbf84b619dd9657a5f86afba00af2a5928" and "fc49a2add1c437f0d1f81d17a7588f9a8a5c448b" have entirely different histories.
0d7097dbf8
...
fc49a2add1
1 changed files with 5 additions and 33 deletions
|
@ -55,38 +55,10 @@ impl Into<i32> for ResultPlay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn round_score(play: char, counter_play: char) -> i32 {
|
pub fn winning(play: Play) -> char {
|
||||||
let coup = Play::from(play); // translate to the play
|
match play {
|
||||||
let counter = Play::from(counter_play); // translate to the play
|
Play::Rock => Play::Paper.into(),
|
||||||
if coup == counter {
|
Play::Paper => Play::Scissors.into(),
|
||||||
(ResultPlay::Draw as i32) + (counter_play as i32)
|
Play::Scissors => Play::Rock.into(),
|
||||||
} else {
|
|
||||||
use Play::*;
|
|
||||||
use ResultPlay::*;
|
|
||||||
match (&coup, &counter) {
|
|
||||||
(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."),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn solve_part1(file_path: &str) -> i32 {
|
|
||||||
let contents =
|
|
||||||
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
|
|
||||||
let lines: Vec<&str> = contents.split('\n').collect();
|
|
||||||
lines
|
|
||||||
.iter()
|
|
||||||
.map(|line| {
|
|
||||||
let first: char = line.chars().nth(0).unwrap_or('R');
|
|
||||||
let last: char = line.chars().nth(2).unwrap_or('R');
|
|
||||||
round_score(first, last)
|
|
||||||
})
|
|
||||||
.collect::<Vec<i32>>()
|
|
||||||
.iter()
|
|
||||||
.sum()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue