aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-215/james-smith/perl/ch-2.pl14
1 files changed, 14 insertions, 0 deletions
diff --git a/challenge-215/james-smith/perl/ch-2.pl b/challenge-215/james-smith/perl/ch-2.pl
index f01950dbd8..88eb2787e7 100644
--- a/challenge-215/james-smith/perl/ch-2.pl
+++ b/challenge-215/james-smith/perl/ch-2.pl
@@ -24,7 +24,21 @@ sub insert_zero_simultaneous {
$c>0?0:1
}
+sub insert_zero_shortcut {
+ my($s,$c) = (0,shift);
+ $_ ? ( $c-= $s>2 && int(($s-1)/2), $s=0, $c>0 || return 1 ) : $s++ for @_,1;
+ 0;
+}
+
+sub insert_zero_simultaneous_shortcut {
+ my($s,$c) = (0,shift);
+ $_ ? ( $c-= $s>2 && $s-2, $s=0, $c>0 || return 1 ) : $s++ for @_,1;
+ 0;
+}
+
is( insert_zero( $_->[0][0], @{$_->[0][1]} ), $_->[1] ) for @TESTS;
is( insert_zero_simultaneous( $_->[0][0], @{$_->[0][1]} ), $_->[1] ) for @TESTS;
+is( insert_zero_shortcut( $_->[0][0], @{$_->[0][1]} ), $_->[1] ) for @TESTS;
+is( insert_zero_simultaneous_shortcut( $_->[0][0], @{$_->[0][1]} ), $_->[1] ) for @TESTS;
done_testing();