login
Numbers such that digits occur at most twice in decimal representation.
1

%I #20 Oct 22 2022 01:57:08

%S 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,

%T 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,

%U 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,112,113,114,115,116,117,118,119,120,121

%N Numbers such that digits occur at most twice in decimal representation.

%C a(n) = n for n <= 110; a(111) = 112.

%C Sequence is finite; last term is 99887766554433221100. There are approximately 10^15 terms in total. - _Charles R Greathouse IV_, Oct 20 2022

%C There are < 141709756697784 terms. - _Michael S. Branicky_, Oct 21 2022

%H Reinhard Zumkeller, <a href="/A262530/b262530.txt">Table of n, a(n) for n = 1..91953</a>, all terms <= 10^5

%t nonDigRepQ[n_] := Max[{Take[Flatten[Tally[IntegerDigits[n]]], {2, -1, 2}]}] < 3; Select[Range[1111], nonDigRepQ[#] &] (* _Ivan N. Ianakiev_, Sep 25 2015 *)

%o (Haskell)

%o import Data.List (delete)

%o a262530 n = a262530_list !! (n-1)

%o a262530_list = filter f [1..] where

%o f = g d10' . show where

%o g _ [] = True

%o g ts (d:ds) = elem d ts && g (delete d ts) ds

%o d10' = d10 ++ d10; d10 = "0123456789"

%o (PARI) isok(n) = {my(v = vecsort(digits(n))); my(d = -1); for(i=1, #v, if (v[i] == d, rl++; if (rl > 2, return (0)); , d = v[i]; rl = 1);); return (1);} \\ _Michel Marcus_, Sep 29 2015

%o (PARI) is(n)=my(d=vecsort(digits(n))); for(i=3,#d, if(d[i]==d[i-2], return(0))); 1 \\ _Charles R Greathouse IV_, Oct 20 2022

%o (Python)

%o from math import factorial

%o from itertools import islice

%o from sympy.utilities.iterables import multiset_combinations as mc

%o from sympy.utilities.iterables import multiset_permutations as mp

%o def agen():

%o yield from range(1, 100)

%o for digits in range(3, 21):

%o for f in "123456789":

%o r = "".join(sorted([f]+[d*2 for d in "0123456789" if d != f]))

%o s = set()

%o for c in mc(r, digits-1):

%o for p in mp(c):

%o s.add(int(f + "".join(p)))

%o yield from sorted(s)

%o print(list(islice(agen(), 120))) # _Michael S. Branicky_, Oct 21 2022

%Y Cf. A010784.

%K nonn,base,fini

%O 1,2

%A _Reinhard Zumkeller_, Sep 24 2015