From aa0f46844a4ad5c452012bba855eebf1f259e15d Mon Sep 17 00:00:00 2001 From: drbaggy Date: Tue, 22 Jun 2021 06:47:46 +0100 Subject: Update README.md --- challenge-118/james-smith/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 -- cgit