diff options
| -rw-r--r-- | challenge-118/james-smith/perl/ch-1.pl | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/challenge-118/james-smith/perl/ch-1.pl b/challenge-118/james-smith/perl/ch-1.pl index 6dadf2038d..df84ea81f1 100644 --- a/challenge-118/james-smith/perl/ch-1.pl +++ b/challenge-118/james-smith/perl/ch-1.pl @@ -32,7 +32,7 @@ my @TESTS = ( is( is_binary_palindrome($_->[0]), $_->[1] ) foreach @TESTS; is( is_binary_palindrome_string($_->[0]), $_->[1] ) foreach @TESTS; -cmpthese( 250_000, { +cmpthese( 100_000, { 'array' => sub { is_binary_palindrome($_->[0]) foreach @TESTS }, 'string' => sub { is_binary_palindrome_string($_->[0]) foreach @TESTS }, } ); @@ -41,10 +41,9 @@ done_testing(); sub is_binary_palindrome_string { ## This is the core perl solution convert to binary using sprintf - ## [this is faster than unpack!] + ## [this is faster than unpack and doesn't have issue with leading 0s!] ## and compare with reverse... - my $t = sprintf '%b', shift; - return ($t eq reverse $t) || 0; + return ( ( $a = sprintf '%b', $_[0] ) eq reverse $a ) || 0; } sub is_binary_palindrome { |
