From 342dd2982ae10c5cdd4f8ffd69972ae47be38940 Mon Sep 17 00:00:00 2001
From: Joe Ardent <code@ardent.nebcorp.com>
Date: Sat, 28 Dec 2024 13:11:42 -0800
Subject: [PATCH] day7, part2

---
 day07/src/main.rs | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/day07/src/main.rs b/day07/src/main.rs
index 5082131..7e9f9ab 100644
--- a/day07/src/main.rs
+++ b/day07/src/main.rs
@@ -3,7 +3,7 @@ use std::collections::HashSet;
 use winnow::{
     PResult, Parser,
     ascii::{dec_uint, newline, space1},
-    combinator::{eof, opt, separated, separated_pair, seq},
+    combinator::{opt, separated, separated_pair, seq},
 };
 
 fn main() {
@@ -86,7 +86,7 @@ fn check(equation: &Equation, pt2: bool) -> bool {
         }
         if process_top {
             let _ = q.pop();
-            if cur_val == target {
+            if cur_val == target && cur_idx == (equation.factors.len() - 1) {
                 return true;
             }
             processed.insert(current);
@@ -112,12 +112,10 @@ fn parse_equation(input: &mut &str) -> PResult<Equation> {
 }
 
 fn parse(input: &str) -> Vec<Equation> {
-    let (equations, _): (Vec<Equation>, _) = seq!(
-        separated(1.., parse_equation, newline),
-        seq!(opt(newline), opt(eof))
-    )
-    .parse(input)
-    .unwrap();
+    let (equations, _): (Vec<Equation>, _) =
+        seq!(separated(1.., parse_equation, newline), opt(newline))
+            .parse(input)
+            .unwrap();
     equations
 }