aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-118/james-smith/README.md10
1 files changed, 10 insertions, 0 deletions
diff --git a/challenge-118/james-smith/README.md b/challenge-118/james-smith/README.md
index 18e4327d69..6350e7cf81 100644
--- a/challenge-118/james-smith/README.md
+++ b/challenge-118/james-smith/README.md
@@ -16,6 +16,9 @@ https://github.com/drbaggy/perlweeklychallenge-club/tree/master/challenge-117/ja
***You are given a positive integer `$N`. Write a script to find out if the binary representation of the given integer is Palindrome. Print `1` if it is otherwise `0`.***
## The solution
+This is a simple code - we convert the number to a binary represenation
+using `sprintf` (actually faster than `unpack`), reverse and `compare`.
+
```perl
sub is_binary_palindrome_string {
my $t = sprintf '%b', shift;
@@ -23,6 +26,13 @@ sub is_binary_palindrome_string {
}
```
+I looked at alternative array based solutions - but these are all
+appreciably slower than using perl "core" string functions - which
+what you would expect. Core functionality will be written in highly
+optimzed "C" and so usually can't be beaten. We have seen this before
+when comparing the speed of `grep` to list utils `first` on small
+to medium lists when the comparison function is simple.
+
# Task 2 - Adventure of Knight
***There are 6 squares with treasures. Write a script to find the