WIP on problem 2
This commit is contained in:
parent
13393c7ea8
commit
1e276e61ff
@ -1 +1,2 @@
|
||||
pub mod prob1;
|
||||
pub mod prob1;
|
||||
pub mod prob2;
|
43
src/prob2/mod.rs
Normal file
43
src/prob2/mod.rs
Normal 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(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user