Improve hand creation
This commit is contained in:
parent
be1cd454fe
commit
a96624e0a0
@ -5,6 +5,12 @@ struct Hand {
|
||||
pub letter: char
|
||||
}
|
||||
|
||||
impl From<&str> for Hand {
|
||||
fn from(s: &str) -> Self {
|
||||
Self { letter: s.0.chars().next().unwrap() }
|
||||
}
|
||||
}
|
||||
|
||||
impl Hand {
|
||||
pub fn score(&self) -> i32 {
|
||||
match self.letter {
|
||||
@ -77,12 +83,14 @@ pub fn run() {
|
||||
.lines()
|
||||
.map(|l| {
|
||||
let hands = l
|
||||
.split(' ')
|
||||
.map(|s|Hand { letter: s.chars().next().unwrap() })
|
||||
.collect::<Vec<_>>();
|
||||
.split_once(' ')
|
||||
.map(|c|
|
||||
(c.0.into(),
|
||||
c.1.into())
|
||||
).unwrap();
|
||||
Round {
|
||||
enemy: hands[0].clone(),
|
||||
me: hands[1].clone(),
|
||||
enemy: hands.0,
|
||||
me: hands.1,
|
||||
}
|
||||
}).map(|r|(r.score(), r.score_b()))
|
||||
.fold((0, 0), |agg, cur|(agg.0 + cur.0, agg.1 + cur.1));
|
||||
|
Loading…
Reference in New Issue
Block a user