aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-06-22 06:47:46 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-06-22 06:47:46 +0100
commitaa0f46844a4ad5c452012bba855eebf1f259e15d (patch)
treed8df63d0ddaef281399f00cc28c9719ef8cb31d3
parentc4edea73d47e0c5cd16b504e43f9e64d12cf60a2 (diff)
downloadperlweeklychallenge-club-aa0f46844a4ad5c452012bba855eebf1f259e15d.tar.gz
perlweeklychallenge-club-aa0f46844a4ad5c452012bba855eebf1f259e15d.tar.bz2
perlweeklychallenge-club-aa0f46844a4ad5c452012bba855eebf1f259e15d.zip
Update README.md
-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