Improve hand creation

This commit is contained in:
max.nuding 2022-12-02 07:48:10 +01:00
parent be1cd454fe
commit a96624e0a0
Failed to extract signature

View File

@ -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));