diff options
| author | Abigail <abigail@abigail.be> | 2021-05-30 16:31:50 +0200 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-05-30 16:31:50 +0200 |
| commit | fd57d548da9fac2cdc00e0bc92e80052e2d6a2c1 (patch) | |
| tree | 322f38020a8440ff946ccadf2ae6b162ed7b2f10 /challenge-114/abigail | |
| parent | 4a8f8b846b6a8b6cd25025cac07a43ffa8f6abe0 (diff) | |
| download | perlweeklychallenge-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')
| -rw-r--r-- | challenge-114/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-114/abigail/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-114/abigail/perl/ch-2.pl | 21 |
3 files changed, 4 insertions, 19 deletions
diff --git a/challenge-114/abigail/README.md b/challenge-114/abigail/README.md index 174d509623..7548aee37d 100644 --- a/challenge-114/abigail/README.md +++ b/challenge-114/abigail/README.md @@ -55,3 +55,4 @@ higher integer is `17` having the same number of `1` bits i.e. `10001`. * [Perl](perl/ch-2.pl) ### Blog +[Higher Integet Set Bits](https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-114-2.html) diff --git a/challenge-114/abigail/blog1.txt b/challenge-114/abigail/blog1.txt new file mode 100644 index 0000000000..aee5ae3122 --- /dev/null +++ b/challenge-114/abigail/blog1.txt @@ -0,0 +1 @@ +https://abigail.github.io/HTML/Perl-Weekly-Challenge/week-114-2.html 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 <>; |
