diff options
Diffstat (limited to 'src/2021/1/mod.rs')
-rw-r--r-- | src/2021/1/mod.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/2021/1/mod.rs b/src/2021/1/mod.rs index 3ba61e2..c01714a 100644 --- a/src/2021/1/mod.rs +++ b/src/2021/1/mod.rs @@ -1,8 +1,10 @@ -pub fn parse(fh: std::fs::File) -> anyhow::Result<Vec<i64>> { - Ok(crate::util::parse::ints(crate::util::parse::lines(fh)).collect()) +use crate::prelude::*; + +pub fn parse(fh: File) -> Result<Vec<i64>> { + Ok(parse::ints(parse::lines(fh)).collect()) } -pub fn part1(ints: Vec<i64>) -> anyhow::Result<i64> { +pub fn part1(ints: Vec<i64>) -> Result<i64> { Ok(ints .windows(2) .map(|a| a[1] - a[0]) @@ -11,7 +13,7 @@ pub fn part1(ints: Vec<i64>) -> anyhow::Result<i64> { .try_into()?) } -pub fn part2(ints: Vec<i64>) -> anyhow::Result<i64> { +pub fn part2(ints: Vec<i64>) -> Result<i64> { Ok(ints .windows(3) .map(|a| a[0] + a[1] + a[2]) @@ -26,11 +28,11 @@ pub fn part2(ints: Vec<i64>) -> anyhow::Result<i64> { #[test] fn test() { assert_eq!( - part1(parse(crate::util::data(2021, 1).unwrap()).unwrap()).unwrap(), + part1(parse(parse::data(2021, 1).unwrap()).unwrap()).unwrap(), 1602 ); assert_eq!( - part2(parse(crate::util::data(2021, 1).unwrap()).unwrap()).unwrap(), + part2(parse(parse::data(2021, 1).unwrap()).unwrap()).unwrap(), 1633 ); } |