diff options
Diffstat (limited to 'src/2020/1/mod.rs')
-rw-r--r-- | src/2020/1/mod.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/2020/1/mod.rs b/src/2020/1/mod.rs index 8ac5e14..31c4c5d 100644 --- a/src/2020/1/mod.rs +++ b/src/2020/1/mod.rs @@ -1,5 +1,8 @@ -pub fn part1() -> anyhow::Result<i64> { - let ints: Vec<_> = data_ints!()?.collect(); +pub fn parse(fh: std::fs::File) -> anyhow::Result<Vec<i64>> { + Ok(crate::util::parse::ints(crate::util::parse::lines(fh)).collect()) +} + +pub fn part1(ints: Vec<i64>) -> anyhow::Result<i64> { for i in &ints { for j in &ints { if i + j == 2020 { @@ -10,8 +13,7 @@ pub fn part1() -> anyhow::Result<i64> { Err(anyhow::anyhow!("no numbers summing to 2020 found")) } -pub fn part2() -> anyhow::Result<i64> { - let ints: Vec<_> = data_ints!()?.collect(); +pub fn part2(ints: Vec<i64>) -> anyhow::Result<i64> { for i in &ints { for j in &ints { for k in &ints { @@ -26,6 +28,12 @@ pub fn part2() -> anyhow::Result<i64> { #[test] fn test() { - assert_eq!(part1().unwrap(), 445536); - assert_eq!(part2().unwrap(), 138688160); + assert_eq!( + part1(parse(crate::util::data(2020, 1).unwrap()).unwrap()).unwrap(), + 445536 + ); + assert_eq!( + part2(parse(crate::util::data(2020, 1).unwrap()).unwrap()).unwrap(), + 138688160 + ); } |