# Numbers with distinct decimal digits

Write a program or function that outputs all positive integers with distinct decimal digits (OEIS: A010784)

Examples:

1 2 3 4 5 6 7 8 9 10 12 13 ...
96 97 98 102 103 ...
123456789 123456798 ... 9876543120 9876543201 9876543210


# Rules

• You can output the list of numbers in any convenient format (string with separators, array, generator, ...)
• The order of the numbers is not important as long as every number appears exactly once
• You can choose if you include zero
• This is the shortest solution wins
• – xnor
Sep 18 at 7:44
• To clarify: should every number appear exactly once, or are repetitions allowed? Sep 18 at 16:37
• @GregMartin "exactly one" means no repetitions (and that all numbers have to appear) Sep 18 at 17:02

import Data.List
nub$nub.show<$>[1..]


Try it online!

Takes each number, removes duplicate digits from its string representation while preserving order, then removes duplicates from the resulting list.

41 bytes

[s|s<-show<$>[1..],s==[x|x<-s,y<-s,x==y]]  Try it online! For both solutions, the resulting list is finite, but attempts to read further elements will not terminate. Adding an upper bound would fix this. # J, 14 bytes ~.~.@":&>i.!14  Attempt This Online! (with 7 instead of 14) Uses xnor's idea: take unique digits from each number and then take unique results of that. # J, 18 bytes I.(=&#=)@":&>i.!14  Attempt This Online! (with 7 instead of 14) 14! is the first factorial that exceeds 10^10. I.(=&#=)@":&>i.!14 !14 large enough number i. all numbers up to that &> for each number, ( )@": stringify and check that, = taking the unique chars =&# keeps the length identical I. output all true indices  • Might it be shorter to take the unique chars of every number, then uniquify the list of results? – xnor Sep 18 at 8:36 • @xnor That's actually a good idea... Sep 18 at 8:43 # 05AB1E, 5 4 bytes ∞€ÙÙ  Outputs an infinite list. Try it online. Explanation: ∞ # Push an infinite list of positive integers: [1,2,3,...] €Ù # Uniquify the digits in each integer Ù # Uniquify this infinite list # (after which this 'filtered' infinite list is output implicitly as result)  • I'd be surprised if it really outputs an infinite list, bearing in mind that the list of numbers with distinct decimal digits is itself finite... Sep 18 at 8:16 • @DominicvanEssen I guess you're partially right, but the same applies to most answers that results in an infinite output. The infinite list in 05AB1E is lazy, so it'll filter it, and then just time out after 60 seconds on TIO, while outputting as much as possible. And if you stop the execution of the program earlier, it'll still output the ones it has processed thus far. Sep 18 at 8:39 • if it ran with unlimited/infinite time, would it ever output? just making sure i understand Sep 18 at 8:40 • my point: programs must terminate by default... does this count as terminating? :P Sep 18 at 8:57 • @KevinCruijssen it might count as outputting a generator or something though since you could (presumably) take this infinite list as input and output indices from it? either way it might be worth bringing up on meta before you go on an edit-spree, especially since nobody's seemed to have issue with it in the past. That being said please do save the old versions if you do edit, the results are still interesting even if they might not be considered "valid" for whatever reason... Sep 18 at 15:44 # K (ngn/k), 12 bytes .'??'$!_1e10


Try it online! (with 1e3 instead of 1e10)

Uses xnor's idea: take unique digits from each number and then take unique results of that. Because the result is a list of strings, .' is necessary to convert them back to numbers.

# K (ngn/k), 15 bytes

&~'/?:'$!_1e10  Try it online! (with 1e3 instead of 1e10) &~'/?:'$!_1e10
!_1e10    0..9999999999
$stringify each number ?:'\ iterate-collect over "uniquify each string" which gives zeroth (original) and first (uniquified) iterations ~'/ 1 if the two are equal, 0 otherwise for each item & output nonzero indices  # Vyxal, 26 bitsv2, 3.25 bytes Þ∞'Þu  Outputs an infinite list. Try it online. Explanation: Þ∞ # Push an infinite positive list: [1,2,3,...] ' '# Filter it by: Þu # All digits in the integer are unique # (after which this filtered infinite list is output implicitly as result)  # Python 3, 49 bytes n=1 while 1/n:10**len({*str(n)})>n!=print(n);n+=1  Try it online! Uses my 10** trick from 2014. Converting the string representation of $$\n\$$ to a set removes duplicates, and we check whether this decreases the length by comparing to $$\10^n\$$, which is bigger than all $$\n\$$-digit number but no $$\(n+1)\$$-digit numbers. The 1/n is used to theoretically halt for large enough n because doubles become zero around 1e-308 due to finite precision. If the program may just continue to run forever after printing all the numbers, this can be: 46 bytes n=0 while[10**len({*str(n)})>n!=print(n)]:n+=1  Try it online! • How does this program choose if it calls print ? Sep 18 at 8:05 • @bsoelch It uses the fact that operator chains short-circuit and won't evaluate further than needed, see this tip. – xnor Sep 18 at 8:07 # JavaScript (SpiderMonkey), 43 bytes for(i=99e9;i;)/(.).*\1/.test(--i)||print(i)  Try it online! (Linked version prints only up to 3 digits to avoid time out) • The SpiderMonkey link gives me a 404. Also, 1e10 will work as well—and it's a lot less performance-heavy. Sep 23 at 18:54 # Nekomata, 3 bytes ŇƊů  Attempt This Online! Outputs a list of lists of digits, without leading zeros. Zero is also output in this way (so appears in the output as an empty list). Ň # nondeterminiatically choose a natural number Ɗ # convert it to a list of decimal digits ů # keep them if they are all unique  # Nekomata, 4 bytes ŇƊůN  Attempt This Online! Outputs a list of lists of digits, without leading zeros. Zero is not part of the output. Works as the shorter answer above, but with an additional N to reject empty lists. # Brachylog, 3 bytes ℕ≜≠  Try it online! This is a generator, the output of this predicate unifies with each possible integer in increasing magnitudes. The try it online link has a header to unify the first 100 values. ### Explanation ℕ A non-negative integer ≜ Pick one of them ≠ All elements (i.e. digits) must be different  # Charcoal, 14 bytes ΦＩ…⁰Ｘχχ¬⊙ι⊖№ιλ  Try it online! Link is to verbose version of code but only goes to 9876 because it would be too slow or run out of memory. Explanation:  … Range from ⁰ Literal integer 0 χ Predefined variable 10 Ｘ Raised to power χ Predefined variable 10 Ｉ Cast to string Φ Filtered where ι Current string ¬⊙ No character satisfies № Count of λ Current character ι In current string ⊖ Is not 1 Implicitly print  # Retina 0.8.2, 27 bytes  9999999999$*¶

$. A(.).*\1  Try it online! Link only goes to 9876 because it would be too slow or run out of memory. Explanation:  9999999999$*¶

$.  List the numbers up to 9999999999. A(.).*\1  Delete those with duplicate digits. # Julia, 45 bytes (r=1:2^34)[allunique.(r.|>x->"$x")].|>println


Attempt This Online!

Any number larger than 10^10 is a suitable upper limit for the range; using 2^34 saves a byte (this is reduces to 2^7 in the linked solution).

# Ruby, 29 30 bytes

p (?0..?9*10).grep_v /(.).*\1/


Try it online!

# Ruby, 47 bytes

f=->a=[*?1..?9],s=""{a.map{|i|f[a-[i],p(s+i)]}}


Try it online!

Link is a demo with only the digits 1..3

This recursively builds up the number from a pool of available digits. Longer than I had hoped for this approach, but efficient.

# Bash, 34

seq -f%.0f 1e10|grep -Ev '(.).*\1'


If you have the jot command installed, you can save 1 byte by replacing the seq command with jot 9876543210.

This is quite slow - I think its been running 2 hours already and is 40% through.

Try it online!

# Jelly, 7 bytes

ȷ10Q€ḌQ


Try it online!

A niladic link returning the full list of numbers. TIO link only returns values <1e5 since otherwise it runs out of memory (and would time out if not)

Uses the same methodology as @KevinCruijssen’s 05AB1E answer so upvote that one too!