fix tests on day 7

This commit is contained in:
kageru 2022-12-15 20:48:04 +01:00
parent 5c09e523e6
commit 606f433196
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2

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