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.

A098067 Consider the succession of single digits of the positive integers: 1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 ... (A007376). This sequence is the lexicographically earliest derangement of the positive integers that produces the same succession of digits.

Original entry on oeis.org

12, 3, 4, 5, 6, 7, 8, 9, 10, 1, 112, 13, 14, 15, 16, 17, 18, 19, 20, 2, 122, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73
Offset: 1

Views

Author

Eric Angelini, Sep 13 2004

Keywords

Comments

Derangement here means that a(n) != n.

Examples

			We must begin with "1,2,3,..." and we cannot have a(1) = 1, so the first possible term is "12". The next term must be the smallest available positive integer not leading to a contradiction, thus "3"; the next one will be "4"; etc. After a(10) = 1, we cannot have a(11) = 11, so we use "112" instead. We are not allowed to use "2" after "19" because the next term would have a leading zero, which is forbidden. - _Eric Angelini_, Aug 12 2008
		

Crossrefs

Programs

  • Mathematica
    lim = 80; f[lst_List, k_] := Block[{L = lst, g, a = {}, m = 0}, g[] := {Set[m, First@ FromDigits@ Append[IntegerDigits@ m, First@ #]], Set[L, Last@ #]} &@ TakeDrop[L, 1]; Do[g[]; While[Or[m == Length@ a + 1, First@ L == 0, MemberQ[a, m]], g[]]; AppendTo[a, m]; m = 0, {k}]; a]; f[Flatten@ Map[IntegerDigits, Range@ lim], Floor[lim - 10^(Log10@ lim - 1)]] (* Michael De Vlieger, Nov 29 2015, Version 10.2 *)
  • Perl
    See Link section.
    
  • Python
    from itertools import count
    def diggen():
        for k in count(1): yield from list(map(int, str(k)))
    def aupton(terms):
        g = diggen()
        alst, aset, , , nextd = [12], {12}, next(g), next(g), next(g)
        for n in range(2, terms+1):
            an, nextd = nextd, next(g)
            while an in aset or an == n or nextd == 0:
                an, nextd = int(str(an) + str(nextd)), next(g)
            alst.append(an); aset.add(an)
        return alst
    print(aupton(72)) # Michael S. Branicky, Dec 03 2021

Extensions

Corrected and extended by Jacques ALARDET and Eric Angelini, Aug 12 2008
Derangement wording introduced by Danny Rorabaugh, Nov 26 2015
Edited by Danny Rorabaugh, Nov 29 2015