day9: formatting
This commit is contained in:
parent
37b645c341
commit
b84b0b04e2
@ -1,6 +1,6 @@
|
|||||||
|
use itertools::Itertools;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Lines};
|
use std::io::{BufRead, BufReader, Lines};
|
||||||
use itertools::Itertools;
|
|
||||||
|
|
||||||
// BOILERPLATE
|
// BOILERPLATE
|
||||||
type InputIter = Lines<BufReader<File>>;
|
type InputIter = Lines<BufReader<File>>;
|
||||||
@ -34,12 +34,8 @@ impl From<&str> for History {
|
|||||||
impl History {
|
impl History {
|
||||||
fn build_row(&mut self) {
|
fn build_row(&mut self) {
|
||||||
let last = self.0.last().unwrap();
|
let last = self.0.last().unwrap();
|
||||||
self.0.push(
|
self.0
|
||||||
last.iter()
|
.push(last.iter().tuple_windows().map(|(a, b)| b - a).collect())
|
||||||
.tuple_windows()
|
|
||||||
.map(|(a, b)| b - a)
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build(&mut self) {
|
fn build(&mut self) {
|
||||||
@ -76,7 +72,10 @@ fn problem1<T: BufRead>(input: Lines<T>) -> i64 {
|
|||||||
history.extrapolate();
|
history.extrapolate();
|
||||||
}
|
}
|
||||||
|
|
||||||
histories.iter().map(|history| history.0.first().unwrap().last().unwrap()).sum()
|
histories
|
||||||
|
.iter()
|
||||||
|
.map(|history| history.0.first().unwrap().last().unwrap())
|
||||||
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROBLEM 2 solution
|
// PROBLEM 2 solution
|
||||||
@ -87,7 +86,10 @@ fn problem2<T: BufRead>(input: Lines<T>) -> i64 {
|
|||||||
history.extrapolate2();
|
history.extrapolate2();
|
||||||
}
|
}
|
||||||
|
|
||||||
histories.iter().map(|history| history.0.first().unwrap().first().unwrap()).sum()
|
histories
|
||||||
|
.iter()
|
||||||
|
.map(|history| history.0.first().unwrap().first().unwrap())
|
||||||
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
Reference in New Issue
Block a user