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