From 47429e2321cb40d6265799651369212ee63e3acc Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Thu, 21 Aug 2025 00:44:21 +0800 Subject: [PATCH] refactor: simplify card operation handling in judge_point24 --- 679_24_game/src/lib.rs | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/679_24_game/src/lib.rs b/679_24_game/src/lib.rs index 6a027dc..664ed4a 100644 --- a/679_24_game/src/lib.rs +++ b/679_24_game/src/lib.rs @@ -22,31 +22,9 @@ impl Solution { left_cards.remove(j); left_cards.remove(i); - let mut new_cards = left_cards.clone(); - new_cards.push(a + b); - stack.push(new_cards); - - let mut new_cards = left_cards.clone(); - new_cards.push(a * b); - stack.push(new_cards); - - let mut new_cards = left_cards.clone(); - new_cards.push(a - b); - stack.push(new_cards); - - let mut new_cards = left_cards.clone(); - new_cards.push(b - a); - stack.push(new_cards); - - if b.abs() > 1e-6 { + for v in [a + b, a * b, a - b, b - a, a / b, b / a] { let mut new_cards = left_cards.clone(); - new_cards.push(a / b); - stack.push(new_cards); - } - - if a.abs() > 1e-6 { - let mut new_cards = left_cards.clone(); - new_cards.push(b / a); + new_cards.push(v); stack.push(new_cards); } }