From de14f133e18bbae95bac0cac0cb88a5737f1ae42 Mon Sep 17 00:00:00 2001 From: Austin White Date: Sun, 6 Mar 2022 02:36:27 -0700 Subject: [PATCH] fix edge case: comptuer picks all remaining items --- 08_Batnum/perl/batnum.pl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/08_Batnum/perl/batnum.pl b/08_Batnum/perl/batnum.pl index a384b963..4280bf38 100644 --- a/08_Batnum/perl/batnum.pl +++ b/08_Batnum/perl/batnum.pl @@ -237,7 +237,12 @@ sub computers_move { $pile_size -= $remove_amount; - printf "COMPUTER TAKES %d AND LEAVES %d.\n", $remove_amount, $pile_size; + if ($pile_size <= 0) { + printf "COMPUTER TAKES %d AND WINS.\n", $remove_amount; + return (1, $pile_size); + } else { + printf "COMPUTER TAKES %d AND LEAVES %d.\n", $remove_amount, $pile_size; + } return (0, $pile_size); }