aboutsummaryrefslogtreecommitdiff
path: root/challenge-114/abigail/perl
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-30 16:31:50 +0200
committerAbigail <abigail@abigail.be>2021-05-30 16:31:50 +0200
commitfd57d548da9fac2cdc00e0bc92e80052e2d6a2c1 (patch)
tree322f38020a8440ff946ccadf2ae6b162ed7b2f10 /challenge-114/abigail/perl
parent4a8f8b846b6a8b6cd25025cac07a43ffa8f6abe0 (diff)
downloadperlweeklychallenge-club-fd57d548da9fac2cdc00e0bc92e80052e2d6a2c1.tar.gz
perlweeklychallenge-club-fd57d548da9fac2cdc00e0bc92e80052e2d6a2c1.tar.bz2
perlweeklychallenge-club-fd57d548da9fac2cdc00e0bc92e80052e2d6a2c1.zip
Blog post for week 114, part 2
Diffstat (limited to 'challenge-114/abigail/perl')
-rw-r--r--challenge-114/abigail/perl/ch-2.pl21
1 files changed, 2 insertions, 19 deletions
diff --git a/challenge-114/abigail/perl/ch-2.pl b/challenge-114/abigail/perl/ch-2.pl
index 681ba2d601..61e2ddf1ea 100644
--- a/challenge-114/abigail/perl/ch-2.pl
+++ b/challenge-114/abigail/perl/ch-2.pl
@@ -18,26 +18,9 @@ use experimental 'lexical_subs';
#
#
-# We will look at the end of the binary expansion of the input number.
-# In particular, we're interested in the last group of 1s. Any positive
-# integer ends when written in binary as:
+# For a description of the algorithm, see
+# https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-114-2.html
#
-# 011...1100...00
-#
-# with 1 or more 1s, and 0 or more 0s at the end (note that we might
-# need to add a leading 0).
-#
-# The next number with the same amount of bits can be found by swapping
-# the '01' pair, and swapping the sequences of 1s and 0s.
-#
-# Code wise, if the input number (after turning it into a binary
-# representation and after adding a leading 0) matches /^(.*)(01)(1*)(0*)$/,
-# the binary representation of the wanted output number is "${1}10${2}${3}".
-#
-# We will be using 'sprintf "0b0%b"' to get the binary representation of
-# a number (including a leading 0 and a leading "0b"), and 'oct' to go
-# from a binary representation back to a number (for which we need the
-# leading "0b").
say oct sprintf ("0b0%b" => $_) =~ s {01(1*)(0*)$} {10$2$1}r while <>;