Math::N...BitCount(3)

πŸ“¦
version 75 Β· 2 versions
, in fedora 43

πŸ’– Math::NumSeq::FibbinaryBitCount β€” the manual, but make it cute πŸ’–

okay bestie so you're reading the User Contributed Perl Documentation page for Math::N...BitCount(3) and honestly? it's giving "tiny module, big brain". let's get into it 🫢


✨ NAME ✨

Math::NumSeq::FibbinaryBitCount β€” number of bits in each fibbinary number

like. it counts bits. in fibbinary numbers. that's the whole vibe πŸ’…


🌸 SYNOPSIS 🌸

use Math::NumSeq::FibbinaryBitCount;
my $seq = Math::NumSeq::FibbinaryBitCount->new;
my ($i, $value) = $seq->next;

literally three lines and you're in. iconic behavior fr fr ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

The number of 1 bits in the i'th fibbinary number.

0, 1, 1, 1, 2, 1, 2, 2, 1, 2, 2, 2, 3, 1, 2, 2, 2, 3, 2, ...
starting i=0

For example i=9 is Fibbinary "1001" so value=2 for 2 1-bits.

The count is 1 for the Fibonacci numbers, as they're "100..00" with a single 1-bit in fibbinary. one (1) bit, one (1) vibe πŸ’š

πŸ”’ Digit 0 πŸ”’

Option "digit => "0"" counts instead the 0-bits

# digit=>"0"   starting i=0
0, 0, 1, 2, 1, 3, 2, 2, 4, 3, 3, 3, 2, 5, 4, 4, 4, 3, 4, ...

i=0 is considered to be an empty set of digits, so it has value=0. This is the same as the "DigitCount" sequence treats i=0.

no cap, an empty set of digits still counts as zero and not "undefined", that's just how it is bestie πŸ™ˆ

0️⃣0️⃣ Digit 00 0️⃣0️⃣

Option "digit => "00"" counts the 0-bits which don't follow a 1-bit, which is equivalent to "00" pairs (including overlapping pairs).

# digit=>"00"   starting i=0
0, 0, 0, 1, 0, 2, 1, 0, 3, 2, 1, 1, 0, 4, 3, 2, 2, 1, 2, ...

For example i=42 is fibbinary "10010000" (42=34+8). It has value=4 for 4 0-bits not counting the two which immediately follow the two 1-bits. Or equivalently 4 "00" pairs

             v  vvv    four 0s which don't follow a 1
i=42   10010000
        ^^ ^^      four "00" pairs, overlaps allowed
            ^^
             ^^

Fibbinary numbers by definition never have consecutive 1-bits, so there's always a 0 following a 1. Excluding those leaves a count of genuinely skipped positions.

When passing the "00" option don't forget to quote it as a string, since a literal number 00 is an octal 0.

$seq = Math::NumSeq::FibbinaryBitCount->new (digit => "00");  # good
$seq = Math::NumSeq::FibbinaryBitCount->new (digit => 00);    # bad
QUOTE. YOUR. STRINGS. πŸ’€ the unquoted 00 is octal zero and it will absolutely not do what you meant. this is the plot twist nobody asked for.

πŸ’… FUNCTIONS πŸ’…

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes.

  • $seq = Math::NumSeq::FibbinaryBitCount->new ()
  • $seq = Math::NumSeq::FibbinaryBitCount->new (digit => $str)

Create and return a new sequence object. making a new one is literally free, go wild ✨

πŸŽ€ Random Access πŸŽ€

  • $value = $seq->ith($i) β€” Return the bit count of the $i'th fibbinary number.
  • $bool = $seq->pred($value) β€” Return true if $value occurs as a bit count, which simply means "$value >= 0".

jump straight to whatever index you want, no walking required, main character energy πŸ‘‘


🌈 SEE ALSO 🌈

Math::NumSeq, Math::NumSeq::Fibbinary, Math::NumSeq::DigitCount, Math::NumSeq::Fibonacci

go read the whole squad, they're all serving πŸ’–


🏠 HOME PAGE 🏠

<http://user42.tuxfamily.org/math-numseq/index.html>


πŸ“œ LICENSE πŸ“œ

Copyright 2011, 2012, 2013, 2014, 2016, 2019, 2020 Kevin Ryde

Math-NumSeq is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

Math-NumSeq is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.

that's the legal bit, don't skip it, the license is the whole reason this is free 🫢

and that's a wrap bestie!! this page is from perl v5.42.0, dated 2025-07-25, and it lives at Math::N...BitCount(3) β€” go count some bits, you got this πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from