summaryrefslogtreecommitdiffstats
path: root/src/2020/1/mod.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-21 04:18:01 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-21 04:18:01 -0500
commit3a5398399221c7986a69c6cc90f7bb70669f39a8 (patch)
treeec4b06df956dbc2aab7c4a2d25a47a65fd4ac81e /src/2020/1/mod.rs
parent5d64e313a46b002205ecfe854555d1e8c94572e0 (diff)
downloadadvent-of-code-3a5398399221c7986a69c6cc90f7bb70669f39a8.tar.gz
advent-of-code-3a5398399221c7986a69c6cc90f7bb70669f39a8.zip
prelude to reduce some typing
Diffstat (limited to 'src/2020/1/mod.rs')
-rw-r--r--src/2020/1/mod.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/2020/1/mod.rs b/src/2020/1/mod.rs
index 31c4c5d..1ed3824 100644
--- a/src/2020/1/mod.rs
+++ b/src/2020/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> {
for i in &ints {
for j in &ints {
if i + j == 2020 {
@@ -10,10 +12,10 @@ pub fn part1(ints: Vec<i64>) -> anyhow::Result<i64> {
}
}
}
- Err(anyhow::anyhow!("no numbers summing to 2020 found"))
+ Err(anyhow!("no numbers summing to 2020 found"))
}
-pub fn part2(ints: Vec<i64>) -> anyhow::Result<i64> {
+pub fn part2(ints: Vec<i64>) -> Result<i64> {
for i in &ints {
for j in &ints {
for k in &ints {
@@ -23,17 +25,17 @@ pub fn part2(ints: Vec<i64>) -> anyhow::Result<i64> {
}
}
}
- Err(anyhow::anyhow!("no numbers summing to 2020 found"))
+ Err(anyhow!("no numbers summing to 2020 found"))
}
#[test]
fn test() {
assert_eq!(
- part1(parse(crate::util::data(2020, 1).unwrap()).unwrap()).unwrap(),
+ part1(parse(parse::data(2020, 1).unwrap()).unwrap()).unwrap(),
445536
);
assert_eq!(
- part2(parse(crate::util::data(2020, 1).unwrap()).unwrap()).unwrap(),
+ part2(parse(parse::data(2020, 1).unwrap()).unwrap()).unwrap(),
138688160
);
}