1
0

WIP on problem 2

This commit is contained in:
Florent DENEF 2022-12-02 11:50:55 +01:00
parent 13393c7ea8
commit 1e276e61ff
2 changed files with 45 additions and 1 deletions

View File

@ -1 +1,2 @@
pub mod prob1;
pub mod prob1;
pub mod prob2;

43
src/prob2/mod.rs Normal file
View File

@ -0,0 +1,43 @@
#[repr(u8)]
pub enum Play {
Rock,
Paper,
Scissors,
}
impl Into<char> for Play {
fn into(self) -> char {
match self {
Play::Rock => 'X',
Play::Paper => 'Y',
Play::Scissors => 'Z',
}
}
}
impl Into<i32> for Play {
fn into(self) -> i32 {
match self {
Play::Rock => 1,
Play::Paper => 2,
Play::Scissors => 3,
}
}
}
pub fn translate(letter: char) -> Option<Play> {
match letter {
'A' => Some(Play::Rock),
'B' => Some(Play::Paper),
'C' => Some(Play::Scissors),
_ => None,
}
}
pub fn winning(play: Play) -> char {
match play {
Play::Rock => Play::Paper.into(),
Play::Paper => Play::Scissors.into(),
Play::Scissors => Play::Rock.into(),
}
}