day7, part2

This commit is contained in:
Joe Ardent 2024-12-28 13:11:42 -08:00
parent b1110f2b6c
commit 342dd2982a

View file

@ -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
}