Cleanup iteration
This commit is contained in:
parent
38f1b5a037
commit
be1cd454fe
@ -1,5 +1,6 @@
|
|||||||
use crate::read;
|
use crate::read;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
struct Hand {
|
struct Hand {
|
||||||
pub letter: char
|
pub letter: char
|
||||||
}
|
}
|
||||||
@ -72,34 +73,27 @@ impl Round {
|
|||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
let input = read("02");
|
let input = read("02");
|
||||||
let rounds = input.lines().map(|l| {
|
let rounds = input
|
||||||
let hands = l.split(' ').collect::<Vec<_>>();
|
.lines()
|
||||||
|
.map(|l| {
|
||||||
|
let hands = l
|
||||||
|
.split(' ')
|
||||||
|
.map(|s|Hand { letter: s.chars().next().unwrap() })
|
||||||
|
.collect::<Vec<_>>();
|
||||||
Round {
|
Round {
|
||||||
enemy: Hand {
|
enemy: hands[0].clone(),
|
||||||
letter: hands.first().unwrap().chars().next().unwrap(),
|
me: hands[1].clone(),
|
||||||
},
|
|
||||||
me: Hand {
|
|
||||||
letter: hands[1].chars().next().unwrap(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}).map(|r|(r.score(), r.score_b()))
|
||||||
).collect::<Vec<_>>();
|
.fold((0, 0), |agg, cur|(agg.0 + cur.0, agg.1 + cur.1));
|
||||||
|
|
||||||
#[cfg(feature = "part1")]
|
#[cfg(feature = "part1")]
|
||||||
{
|
{
|
||||||
let a: i32 = rounds
|
eprintln!("Day 2, Part 01: {}", rounds.0);
|
||||||
.iter()
|
|
||||||
.map(|r|r.score())
|
|
||||||
.sum();
|
|
||||||
eprintln!("Day 2, Part 01: {}", a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "part2")]
|
#[cfg(feature = "part2")]
|
||||||
{
|
{
|
||||||
let b: i32 = rounds
|
eprintln!("Day 2, Part 02: {}", rounds.1);
|
||||||
.iter()
|
|
||||||
.map(|r|r.score_b())
|
|
||||||
.sum();
|
|
||||||
eprintln!("Day 2, Part 02: {}", b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user