summaryrefslogtreecommitdiffstats
path: root/src/2021/10/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/2021/10/mod.rs')
-rw-r--r--src/2021/10/mod.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/2021/10/mod.rs b/src/2021/10/mod.rs
index 29cced2..ae311e8 100644
--- a/src/2021/10/mod.rs
+++ b/src/2021/10/mod.rs
@@ -1,6 +1,12 @@
-pub fn part1() -> anyhow::Result<i64> {
+pub fn parse(
+ fh: std::fs::File,
+) -> anyhow::Result<impl Iterator<Item = String>> {
+ Ok(crate::util::parse::lines(fh))
+}
+
+pub fn part1(lines: impl Iterator<Item = String>) -> anyhow::Result<i64> {
let mut total = 0;
- for line in data_lines!()? {
+ for line in lines {
let mut open = vec![];
for c in line.chars() {
match c {
@@ -38,9 +44,9 @@ pub fn part1() -> anyhow::Result<i64> {
Ok(total)
}
-pub fn part2() -> anyhow::Result<i64> {
+pub fn part2(lines: impl Iterator<Item = String>) -> anyhow::Result<i64> {
let mut scores = vec![];
- for line in data_lines!()? {
+ for line in lines {
let mut open = vec![];
let mut skip = false;
for c in line.chars() {
@@ -92,6 +98,12 @@ pub fn part2() -> anyhow::Result<i64> {
#[test]
fn test() {
- assert_eq!(part1().unwrap(), 166191);
- assert_eq!(part2().unwrap(), 1152088313);
+ assert_eq!(
+ part1(parse(crate::util::data(2021, 10).unwrap()).unwrap()).unwrap(),
+ 166191
+ );
+ assert_eq!(
+ part2(parse(crate::util::data(2021, 10).unwrap()).unwrap()).unwrap(),
+ 1152088313
+ );
}