From 606f4331962da73492ca244b31d9c2454ea52b4e Mon Sep 17 00:00:00 2001 From: kageru Date: Thu, 15 Dec 2022 20:48:04 +0100 Subject: [PATCH] fix tests on day 7 --- 2022/src/bin/day11.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/2022/src/bin/day11.rs b/2022/src/bin/day11.rs index 758a288..5720c13 100644 --- a/2022/src/bin/day11.rs +++ b/2022/src/bin/day11.rs @@ -31,11 +31,13 @@ fn parse_input(raw: &str) -> Parsed { let true_dst = parse_num(&if_true[29..]); let false_dst = parse_num(&if_false[30..]); let op = op.as_bytes(); - let op = match (op[23], op[25]) { - (b'+', b'o') => MonkeyOp::Add(None), - (b'+', x) => MonkeyOp::Add(Some((x - b'0') as _)), - (b'*', b'o') => MonkeyOp::Mul(None), - (b'*', x) => MonkeyOp::Mul(Some((x - b'0') as _)), + let op = match (op[23], op[25], op.get(26).copied()) { + (b'+', b'o', _) => MonkeyOp::Add(None), + (b'+', x, None) => MonkeyOp::Add(Some((x - b'0') as _)), + (b'+', x, Some(y)) => MonkeyOp::Add(Some(((x - b'0') * 10 + y - b'0') as _)), + (b'*', b'o', _) => MonkeyOp::Mul(None), + (b'*', x, None) => MonkeyOp::Mul(Some((x - b'0') as _)), + (b'*', x, Some(y)) => MonkeyOp::Mul(Some(((x - b'0') * 10 + y - b'0') as _)), _ => unreachable!(), }; Monkey { inspection_count: 0, items, op, div_test, true_dst, false_dst }