cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A347688 Let c (resp. C) be the smallest (resp. largest) number that can be obtained by cyclically permuting the digits of n; a(n) = C - c.

Original entry on oeis.org

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 9, 18, 27, 36, 45, 54, 63, 72, 18, 9, 0, 9, 18, 27, 36, 45, 54, 63, 27, 18, 9, 0, 9, 18, 27, 36, 45, 54, 36, 27, 18, 9, 0, 9, 18, 27, 36, 45, 45, 36, 27, 18, 9, 0, 9, 18, 27, 36, 54, 45, 36, 27, 18, 9, 0, 9, 18, 27, 63, 54, 45, 36, 27, 18, 9, 0, 9, 18, 72, 63, 54, 45, 36, 27, 18, 9, 0, 9, 81, 72, 63, 54, 45, 36, 27, 18, 9, 0, 99, 99, 189, 279, 369, 459, 549, 639, 729, 819, 99, 0, 99
Offset: 0

Views

Author

N. J. A. Sloane, Sep 22 2021, following a suggestion from Joseph Rozhenko

Keywords

Comments

Agrees with A151949 for n <= 101.
All terms are multiples of 9 (cf. A347689).
Repeatedly applying the operation of subtracting the smallest cyclic permutation from the largest produces interesting sequences. It appears that n-digit numbers converge to a small number m << n of loops. Any 3-digit number converges to one of two loops of length 3: (189, 729, 675) and (378, 459, 486); any 4-digit number to either of (189, 729, 675) or a loop of length 25; any 5-digit number to one of three loops of length 3: (38007, 79335, 59778), (48780, 82926, 65853), or (29889, 69003, 89667), and so on. For 6-digit numbers there are 10 loops (of lengths 1, 2, 3, 10, 12 or 60). - Joseph Rozhenko, Oct 05 2021
For any cyclic number N, there must exist a cyclic permutation P of N for which a(P) = P. - Joseph Rozhenko, Oct 07 2021
An interesting plot of this sequence comes up when the axes are not n vs. a(n), but rather C vs. c. In other words, each number a(n) is represented on the X axis by C (largest number that can be obtained by cyclically permuting the digits of n) and on the Y axis as c (smallest number that can be obtained by cyclically permuting the digits of n). - Joseph Rozhenko, Jan 26 2022

Examples

			If n = 102, c = 21, C = 210, a(102) = 210 - 21 = 189.
		

Crossrefs

Programs

  • Maple
    A347688 := proc(n)
            local dgs,C,c,ndgs,r ;
            dgs := convert(n,base,10) ;
            ndgs := nops(dgs) ;
            C := digcatL(dgs) ;
            c := C ;
            for r from 0 to ndgs-1 do
                    C := max(C,digcatL(dgs)) ;
                    c := min(c,digcatL(dgs)) ;
                    dgs := ListTools[Rotate](dgs,1) ;
            end do:
            C-c ;
    end proc: # R. J. Mathar, Sep 27 2021
  • Mathematica
    {0}~Join~Table[First@Differences@MinMax[FromDigits/@(RotateLeft[IntegerDigits@n,#]&/@Range@IntegerLength@n)],{n,112}] (* Giorgos Kalogeropoulos, Sep 22 2021 *)
  • PARI
    a(n, base=10) = { my (c=n, C=n, d=digits(n, base)); for (k=1, #d, my (r=fromdigits(concat(d[k+1..#d], d[1..k]), base)); c=min(c, r); C=max(C, r)); C-c } \\ Rémy Sigrist, Sep 22 2021
    
  • Python
    def a(n):
        s = str(n)
        cyclic_perms = [int("".join(s[i:] + s[:i])) for i in range(len(s))]
        c, C = min(cyclic_perms), max(cyclic_perms)
        return C - c
    print([a(n) for n in range(113)]) # Michael S. Branicky, Sep 26 2021

Formula

a(n) = 0 iff n belongs to A010785. - Rémy Sigrist, Sep 22 2021

Extensions

More than the usual number of terms are shown in order to distinguish this from similar sequences.