day9: formatting

This commit is contained in:
Keenan Tims 2023-12-08 21:41:30 -08:00
parent 37b645c341
commit b84b0b04e2
Signed by: ktims
GPG Key ID: 11230674D69038D4

View File

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