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 }