Math::N...gitRadix(3)

๐Ÿ“ฆ
version 75 ยท 2 versions
, in fedora 43

๐Ÿ’– Math::NumSeq::RepdigitRadix ๐Ÿ’–

okay so this is a page from the User Contributed Perl Documentation โ€” it's Math::NumSeq::RepdigitRadix and it's about to tell you which radix makes a number go full repdigit โœจ buckle up bestie


๐ŸŒธ NAME ๐ŸŒธ

Math::NumSeq::RepdigitRadix โ€” it's giving radix in which i is a repdigit ๐Ÿ’…


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

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

๐ŸŽ€ DESCRIPTION ๐ŸŽ€

So the value this sequence spits out is the radix in which i is a repdigit, and the vibe goes:

2, 0, 0, 2, 3, 4, 5, 2, 3, 8, 4, 10, etc
starting i=0

okay so let's break it down fr fr:

  • i=0 is just taken to be a repdigit "00" in base 2. iconic of it honestly.
  • i=1 and i=2 are not repdigits in any radix. not even one. tragic.
  • then i=3 is repdigit "11" in base 2 ๐Ÿ‘‘
  • any i>=3 is at worst a repdigit "11" in base i-1, but it may be a repdigit in a smaller base. for example i=8 is "22" in base 3 ๐Ÿ“
Is this behaviour for i=0,1,2 any good? Perhaps it will change. (yes bestie, the author is literally asking. we love an honest king.)

๐Ÿ‘‘ FUNCTIONS ๐Ÿ‘‘

See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence classes. (iykyk ๐Ÿ’œ)

  • "$seq = Math::NumSeq::RepdigitRadix->new ()" โ€” Create and return a new sequence object. boom, you have a sequence ๐Ÿ’–

๐ŸŽฒ Random Access ๐ŸŽฒ

  • "$value = $seq->ith($i)" โ€” Return the radix in which $i is a repdigit.
โš ๏ธ The current code relies on factorizing $i, and a hard limit of 2**32 is placed on $i in the interests of not going into a near-infinite loop. so like, do not send it a big number, it will simply not have a good time ๐Ÿ˜ญ

๐Ÿงฎ FORMULAS ๐Ÿงฎ

ith() Value

ith() looks for the smallest radix r for which there's a digit d and length len satisfying

i = d * repunit(len)
i = d * (r^(len-1) + r^(len-2) + ... + r^2 + r + 1)

The current approach is to consider repdigit lengths successively from log2(i) downwards and candidate digits d from among the divisors of i.

for len=log2(i) down to 2
  for d each divisor of i, descending
    r = nthroot(i/d, len-1)
    if r >= r_found then next len
    if r <= d then next divisor
    if (r^len-1)/(r-1) == i/d then r_found=r, next len

if no r_found then r_found = i-1

For a given d the radix r to give i would be

i/d = r^(len-1) + ... + r + 1

but it's enough to calculate

i/d = r^(len-1)
r = floor nthroot(i/d, len-1)

and then power up to see if it gives the desired i/d.

repunit(len) = r^(len-1) + ... + r + 1
             = (r^len - 1) / (r-1)
check if equals i/d

floor(nthroot()) is never too small, since an r+1 from it would give

(r+1)^(len-1) = r^(len-1) + binomial*r^(len-2) + ... + 1
              > r^(len-1) +          r^(len-2) + ... + 1

Divisors are taken in descending order so the radices r are in increasing order. So if a repdigit is found in a given len then it's the smallest of that length and can go on to other lengths. slay ๐Ÿซถ

The lengths can be considered in any order but the current code goes from high to low since a bigger length means a smaller maximum radix within that length (occurring when d=1, ie. a repunit), so it might establish a smaller "r_found" and a smaller r_found limits the number of divisors to be tried in subsequent lengths. But does that actually happen often enough to make any difference? ๐Ÿค” (asking the real questions)


ith() Other Possibilities

When len is even the repunit part r^(len-1)+...+1 is a multiple of r+1. Can that cut the search? For a given divisor the r is found easily enough by nthroot, but maybe i with only two prime factors can never be an even length>=4 repdigit, or something like that. โœจ open research question bestie โœจ


๐ŸŒˆ SEE ALSO ๐ŸŒˆ

  • Math::NumSeq
  • Math::NumSeq::RepdigitAny

๐Ÿ  HOME PAGE ๐Ÿ 

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


๐Ÿ“œ LICENSE ๐Ÿ“œ

Copyright 2010, 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/>.


and that's the whole thing bestie, no cap, every last detail preserved ๐Ÿ’–โœจ๐ŸŽ€

perl v5.42.0 ยท 2025-07-25 โ€” mwah, go read it again if you need to, ily ๐Ÿซถ๐Ÿ’…

๐Ÿ“ฆ where this page comes from