37 lines
911 B
Rust
37 lines
911 B
Rust
use crate::days::Solution;
|
|
|
|
pub struct Day01;
|
|
|
|
impl Solution for Day01 {
|
|
type Input = Vec<i16>;
|
|
|
|
fn parse(&self, data: &str) -> Self::Input {
|
|
data.split("\n")
|
|
.map(|l| {
|
|
let mut chars = l.chars();
|
|
let first = chars.next();
|
|
let num = chars.collect::<String>().parse::<i16>();
|
|
|
|
match (first, num) {
|
|
(Some('L'), Ok(n)) => -1 * n,
|
|
(Some('R'), Ok(n)) => n,
|
|
_ => 0,
|
|
}
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
fn part1(&self, input: &Self::Input) -> usize {
|
|
input
|
|
.iter()
|
|
.fold((50, 0), |(sum, res), x| match (sum + x) % 100 {
|
|
0 => (0, res + 1),
|
|
newsum => (newsum, res),
|
|
})
|
|
.1
|
|
}
|
|
|
|
fn part2(&self, input: &Self::Input) -> usize {
|
|
0
|
|
}
|
|
}
|