Print all lexicographically increasing numbers under 10000

32

3

A lexicographically increasing number is an integer whose digits are in strictly increasing order. Print all lexicographically increasing numbers under 10000.

Here are lines of the expected output:

0
1
2
3
4
5
6
7
8
9
12
13
14
15
16
17
18
19
23
24
25
26
27
28
29
34
35
36
37
38
39
45
46
47
48
49
56
57
58
59
67
68
69
78
79
89
123
124
125
126
127
128
129
134
135
136
137
138
139
145
146
147
148
149
156
157
158
159
167
168
169
178
179
189
234
235
236
237
238
239
245
246
247
248
249
256
257
258
259
267
268
269
278
279
289
345
346
347
348
349
356
357
358
359
367
368
369
378
379
389
456
457
458
459
467
468
469
478
479
489
567
568
569
578
579
589
678
679
689
789
1234
1235
1236
1237
1238
1239
1245
1246
1247
1248
1249
1256
1257
1258
1259
1267
1268
1269
1278
1279
1289
1345
1346
1347
1348
1349
1356
1357
1358
1359
1367
1368
1369
1378
1379
1389
1456
1457
1458
1459
1467
1468
1469
1478
1479
1489
1567
1568
1569
1578
1579
1589
1678
1679
1689
1789
2345
2346
2347
2348
2349
2356
2357
2358
2359
2367
2368
2369
2378
2379
2389
2456
2457
2458
2459
2467
2468
2469
2478
2479
2489
2567
2568
2569
2578
2579
2589
2678
2679
2689
2789
3456
3457
3458
3459
3467
3468
3469
3478
3479
3489
3567
3568
3569
3578
3579
3589
3678
3679
3689
3789
4567
4568
4569
4578
4579
4589
4678
4679
4689
4789
5678
5679
5689
5789
6789

This is a code golf challenge! Shortest answer wins!

(P.S. looking for a python solution)

Varun Patro

Posted 2018-11-16T19:08:58.283

Reputation: 429

3do we need to print them on separate lines or is space-separated OK? – Giuseppe – 2018-11-16T19:29:17.793

3

Welcome to PPCG! Nice first challenge. For future challenges, I can recommend using the Sandbox to refine a challenge and get meaningful feedback before posting it to main.

– AdmBorkBork – 2018-11-16T19:38:53.707

4To expand on @Giuseppe's question, can we output separated by commas, spaces, in array format [0,1,...], etc. or must we output each number on a separate line? – ETHproductions – 2018-11-16T19:42:47.457

each number must be printed on a new line. – Varun Patro – 2018-11-16T19:52:51.330

10Do the numbers need to be in a specific order, or do they just need to all exist? – Kamil Drakari – 2018-11-16T19:56:30.017

2Are leading zeroes allowed? – gastropner – 2018-11-16T20:23:54.913

14@VarunPatro, please update the challenge to explicitly state that each number by on a separate line (although I'd recommend against that requirement) and make sure to inform any existing solutions that don't do so. – Shaggy – 2018-11-16T20:32:02.710

The md5sum of the (correct) output is 37fd279401e9ba57c8ed54e7eacb49d2. – None – 2018-12-09T13:35:14.500

Answers

31

Python 2, 56 bytes

for n in range(9999):
 if eval('<'.join(`n`))**n:print n

Try it online!

Converts each number like 124 to an expression 1<2<4 and evaluates it to check if the digits are sorted,

A hiccup happens for one-digit numbers giving an expression that just is the number itself. This causes 0 to evaluate to a Falsey value even though it should be printed. This is fixed by a trick suggested by Erik the Outgolfer of doing **n, which gives truthy value 0**0 for n=0 and doesn't affect the truth value otherwise.

xnor

Posted 2018-11-16T19:08:58.283

Reputation: 115 687

What does the \`` do in`n``? – BruceWayne – 2018-11-16T21:58:24.083

1@BruceWayne It takes the string representation. This was removed in Python 3. – xnor – 2018-11-16T22:00:49.743

5

@BruceWayne Note that it's the same as the repr() function, not the str() function. They aren't always the same. Here's an example.

– mbomb007 – 2018-11-16T22:39:23.047

1@mbomb007 thanks for that comment! I would have thought it was str() equivalent. – BruceWayne – 2018-11-16T22:48:12.853

https://docs.python.org/2/library/functions.html#func-repr – mbomb007 – 2018-11-16T22:49:46.453

2

We can handle the 0 case with a bit of trickery.

– xsot – 2018-11-17T16:04:25.533

For OP: Oh, and don't use eval in real code, just in code golf. – user202729 – 2018-11-18T11:11:45.817

13

Python 2, 55 bytes

i=0
exec"print i\ni+=1\nif eval('<'.join(`i`)):1;"*7000

Try it online!

xsot

Posted 2018-11-16T19:08:58.283

Reputation: 5 069

11

Haskell, 50 bytes

unlines[s|s<-show<$>[0..6^5],s==scanl1(max.succ)s]

Try it online!

Outputs a multiline string. We check that the number s increasing using s==scanl1(max.succ)s, a variant of the usual sortedness check s==scanl1 max s that ensures strict sortedness by incrementing each digit character before taking the maximum of it and the next digit.

Ourous saved a byte by using 6^5 as the upper bound in place of a 4-digit number.

xnor

Posted 2018-11-16T19:08:58.283

Reputation: 115 687

8

Japt -R, 12 11 8 bytes

L²Ç¶ìüÃð

Test it

L            :100
 ²           :Squared
  Ç          :Map the range [0,L²)
    ì        :  Split to a digit array
     ü       :  For the sake of simplicity*, let's say: Sort & deduplicate
             :  Implicitly rejoin to an integer
   ¶         :  Test for equality with original number
      Ã      :End map
       ð     :Get 0-based indices of truthy elements
             :Implicitly join with newlines and output

*Or, to offer a better explanation: the ü method sorts an array and splits it into equal elements (e.g., [8,4,8,4].ü() -> [[4,4],[8,8]]) and then, in what seems to be a strange quirk and hopefully not a bug, the ì method, when converting the array back to a number, takes the first element of each nested array, rather than first flattening the array, which is what I expected when I tried this trick (e.g., [[4,4],[8,8]].ì() -> 48).

Shaggy

Posted 2018-11-16T19:08:58.283

Reputation: 24 623

1Nice. Similar to what I had: L²Ç¥ì ü ¬Ãð – Oliver – 2018-11-16T19:39:39.413

2I have to say, that ü trick you guys used is genius :-) @Oliver – ETHproductions – 2018-11-16T19:45:47.663

1@Oliver, you must have posted that as I was updating; great minds ... :) – Shaggy – 2018-11-16T19:48:18.880

@ETHproductions, like most things, I tried it on a whim - amazed it works. – Shaggy – 2018-11-16T19:48:59.247

8

Jelly, 7 bytes

9ŒPḌḣ⁹Y

Try it online!

How it works

9ŒPḌḣ⁹Y  Main link. No arguments.

9        Set the return value to 9.
 ŒP      Powerset; promote 9 to [1, ..., 9] and generate all subsets.
   Ḍ     Undecimal; map the subsets of digits to the integers they represent.
     ⁹   Yield 256.
    ḣ    Dyadic head; take the first 256 elements of the integer list.
      Y  Separate the result by linefeeds.

Dennis

Posted 2018-11-16T19:08:58.283

Reputation: 196 637

2I'm trying to figure out how 0 gets included here but I don't know Jelly. Am I correct that Jelly's powerset includes the empty array which then gets converted to 0 when "undecimaled"? – Shaggy – 2018-11-17T00:21:05.393

1Yes, that's exactly what happens. – Dennis – 2018-11-17T00:37:28.647

6

R, 62 49 bytes

`[`=write;0[1];for(i in 1:4)combn(1:9,i)[1,i,,""]

Try it online!

Because combn iterates through its input in the order given, it's easy to create all the lexicographically increasing integers, printing them out in order. write prints them each i-digit number in lines of width i, neatly fulfilling the newline requirement as well.

Giuseppe

Posted 2018-11-16T19:08:58.283

Reputation: 21 077

great idea exploiting combn ! – digEmAll – 2018-11-17T14:36:13.283

Extremely clever aliasing! – J.Doe – 2018-11-18T12:15:41.500

6

Perl 6, 25 bytes

[<](.comb)&&.say for ^1e4

-1 byte thanks to nwellnhof

Try it online!

.comb produces a list of the digits of each number, and [<] does a less-than reduction on that list, equivalent to: digit1 < digit2 < ... < digitN.

Sean

Posted 2018-11-16T19:08:58.283

Reputation: 4 136

2[<](.comb)&&.say saves a byte. – nwellnhof – 2018-11-17T09:56:13.743

This is surprisingly readable. (I already know a little Perl 6, but still...) – J-L – 2018-11-19T20:38:44.613

5

PowerShell, 42 40 bytes

0..1e4|?{-join("$_"|% t*y|sort -u)-eq$_}

Try it online!

Loop from 0 to 1e4 (i.e., 10000). Pull out those objects where |?{...} the number as a string $_ is -equal to the number cast toCharArray and then sorted with the -unique flag. In other words, only numbers that are the same as their sorted and deduplicated strings. Each of those are left on the pipeline and output is implicit.

AdmBorkBork

Posted 2018-11-16T19:08:58.283

Reputation: 41 581

5

Haskell, 56 55 bytes

Edit: -1 byte thanks to @Ourous

mapM print$filter(and.(zipWith(<)<*>tail).show)[0..6^5]

Try it online!

nimi

Posted 2018-11-16T19:08:58.283

Reputation: 34 639

4

Pyth, 10 bytes

jiRThc2yS9

Try it online!

How it works

jiRThc2yS9
        S9  Yield [1, 2, 3, 4, 5, 6, 7, 8, 9].
       y    Take all 512 subsets.
     c2     Split the array of subsets into 2 pieces (256 subsets each).
    h       Head; take the first piece.
 iRT        Convert each subset from base 10 to integer.
j           Separate by newlines.

Dennis

Posted 2018-11-16T19:08:58.283

Reputation: 196 637

3

Common Lisp, 74 72 bytes

(dotimes(i 7e3)(format(apply'char<(coerce(format()"~d"i)'list))"~d~%"i))

Try it online!

-2 bytes thank to @Shaggy!

Renzo

Posted 2018-11-16T19:08:58.283

Reputation: 2 260

3

J, 26 bytes

,.(#~(-:/:~@~.)@":"0)i.1e4

Try it online!

explanation

,. (#~ (-: /:~@~.)@":"0) i.1e4
                         i.1e4  NB. list 0 to 9999
                     "0         NB. for each number in the input list
                  @":"0         NB. convert it to a string and
   (#~ (         )              NB. remove any not passing this test:
        -:                      NB. the string of digits matches
              @~.               NB. the nub of the digits (dups removed)
           /:~                  NB. sorted
,.                              NB. ravel items: take the result of all that
                                NB. and turn it into a big column

Jonah

Posted 2018-11-16T19:08:58.283

Reputation: 8 729

3

Perl 5, 47 bytes

map{$_&&s/.(?=(.))/$1-$&/gre=~/0|-/||say}0..1E4

Try it online!

Older:

52 bytes

Xcali

Posted 2018-11-16T19:08:58.283

Reputation: 7 671

3

05AB1E (legacy), 8 bytes

4°ÝD€êû

Try it online!

Works in the new version of 05AB1E as well but is painfully slow for some reason.

How?

4°ÝD€êû – Full program.
4°Ý      – Push [0 ... 10000].
   Dې   РPush each integer in [0 ... 10000] sorted and deduplicated at the same time.
      û – And join the interection of the two lists by newlines.

Mr. Xcoder

Posted 2018-11-16T19:08:58.283

Reputation: 39 774

Nice answer. Better than the 9 byter I had (which only works in the legacy).

– Kevin Cruijssen – 2018-11-19T13:54:23.137

2

Jelly, 13 9 8 bytes

Saved 5 bytes thanks to @Dennis

9œcⱮ4ẎŻY

Try it online!

Explanation

Generates all lexicographically increasing numbers below 10000 by taking the digits [1...9] and finding all combinations of length ≤ 4.

9œcⱮ4ẎŻY    Main link. Arguments: none
9           Yield 9.
   Ɱ4       For each n in [1...4]:
 œc           Yield the combinations of the range [1...9] of length n.
     Ẏ      Tighten; dump each of the 4 lists generated into the main list.
      Ż     Prepend a 0 to the list.
       Y    Join on newlines.

Jelly, 11 10 9 bytes

Saved a byte thanks to @EriktheOutgolfer

ȷ4Ḷ<ƝẠ$ƇY

Try it online!

Explanation

Filters through the range, keeping the numbers that are lexicographically increasing.

ȷ4Ḷ<ƝẠ$ƇY    Main link. Arguments: none
ȷ4           Yield 10^4 (10000).
  Ḷ          Generate the range [0...10000).
       Ƈ     Filter; yield only the numbers where this link return a truthy value.
      $        Run these two links and yield the result.
    Ɲ            For each pair of items (digits) in the number:
   <               Check whether the left digit is less than the right digit.
     Ạ           All; check that every comparison yielded true.
               This yields whether the digits are strictly increasing.
        Y    Join the filtered list on newlines.

ETHproductions

Posted 2018-11-16T19:08:58.283

Reputation: 47 880

2

Python 2, 64 61 bytes

lambda:[x for x in range(9999)if sorted(set(`x`))==list(`x`)]

Try it online!

Gets the unique characters of the integer's string representation, sorts them, and compares the result to the original number.

Triggernometry

Posted 2018-11-16T19:08:58.283

Reputation: 765

You can save a byte by using range(9999) or any other number between 6790 and 9999. Our solutions are almost identical BTW :) – James – 2018-11-16T19:47:24.590

@DJMcMayhem But then it wouldn't check ALL numbers under 10,000....:P Thanks! Sometimes I get too literal with these challenges. – Triggernometry – 2018-11-16T19:50:44.070

2

Wolfram Language (Mathematica), 36 bytes

After I wrote this, it was clarified that each number must be on a new line, so +7 bytes for the Print/@.

This method takes advantage of the fact that the Subsets function 1) doesn't replicate any digits and 2) sorts the output by set size and set contents. FromDigits assembles each list of digits.

-1 byte thanks to @Mr.Xcoder

Print/@FromDigits/@Range@9~Subsets~4

Try it online!

Kelly Lowder

Posted 2018-11-16T19:08:58.283

Reputation: 3 225

1Print/@FromDigits/@Range@9~Subsets~4 for 36 bytes. – Mr. Xcoder – 2018-11-17T14:32:12.637

Funny, I thought of that and just didn't do it because I thought ~ had higher precedence than @ – Kelly Lowder – 2018-11-19T02:55:52.157

2

Python 2, 61 bytes

for i in range(9999):
 if list(`i`)==sorted(set(`i`)):print i

Try it online!

Chas Brown

Posted 2018-11-16T19:08:58.283

Reputation: 8 959

2

V, 41 bytes

7000ïÎaÛ
Îy$úúP
Ç^¨ä*©±$/d
ÎãlD
爱/d
HO0

Try it online!

Hexdump:

00000000: 3730 3030 efce 61db 0ace 7924 fafa 500a  7000..a...y$..P.
00000010: c75e a8e4 2aa9 b124 2f64 0ace e36c 440a  .^..*..$/d...lD.
00000020: e788 b12f 640a 484f 30                   .../d.HO0

James

Posted 2018-11-16T19:08:58.283

Reputation: 54 537

2

Charcoal, 19 bytes

ΦEXχ⁴Iι¬Φι∧쬋§ι⊖μλ

Try it online! Link is to verbose version of code. Explanation:

   χ                Predefined variable 10
  X                 To the power
    ⁴               Literal 4
 E                  Map over implicit range
      ι             Current value
     I              Cast to string
Φ                   Filter over strings where
         ι          Current string
        Φ           Filtered over characters
           μ        Character index (is nonzero)
          ∧         And
                 μ  Character index
                ⊖   Decremented
              §     Indexed into
               ι    Current string
            ¬       Is not
             ‹      Less than
                  λ Current character
       ¬            Results in an empty string
                    Implicitly print matches on separate lines

Neil

Posted 2018-11-16T19:08:58.283

Reputation: 95 035

2

JavaScript REPL, 64 bytes

A bit of pub golf so probably far from optimal.

(f=n=>n&&f(n-1)+([...n+``].every(x=>y<(y=x),y=0)?`
`+n:``))(7e3)

Try it online

Yes, doing it without an IIFE would be a few bytes shorter but that throws an overflow error when called, which would normally be fine as we can assume infinite memory for the purposes of code golf but, to me, doesn't seem to be in the spirit of KC challenges.

Shaggy

Posted 2018-11-16T19:08:58.283

Reputation: 24 623

I don't get an overflow error without an IIFE. – Spitemaster – 2018-11-17T04:32:27.337

Is this a function submission or a full program? If not, you should either count the console.log or relabel your submission as JavaScript REPL. – Dennis – 2018-11-21T02:58:54.223

2

K (ngn/k) / K (oK), 32 30 26 bytes

Solution:

`0:$&&/'1_'>':'" ",'$!9999

Try it online!

Explanation:

`0:$&&/'1_'>':'" ",'$!9999 / the solution
                     !9999 / range 0..9998 (could use !6890)
                    $      / string
               " ",'       / prepend " " to each (lower than "0" in ascii)
            >:'            / greater-than each-previous?
         1_'               / drop first result from each
      &/'                  / max (&) over (/)
    &                      / indices where true
   $                       / convert to string
`0:                        / print to stdout

streetster

Posted 2018-11-16T19:08:58.283

Reputation: 3 635

2

C# (Visual C# Interactive Compiler), 102 101 73 ... 72 bytes

-12 and -4 thanks @Dennis!

for(var i=0;i<7e3;i++)if((i+"").Aggregate((a,b)=>a<b?b:':')<58)Print(i);

Try it online!

Each integer from 0 to 7k tested by first converting it into a string. Leveraging the fact that C# treats strings as character enumerables and LINQ, an aggregate is calculated for each character enumerable as follows:

  • compare the accumulated value with the current character
  • if the current character is greater than the accumulation, return the current character
  • otherwise return : which is greater than 9

If the result of this is less than : (ASCII 58), then the number has lexicographically increasing digits.

dana

Posted 2018-11-16T19:08:58.283

Reputation: 2 541

Doesn't the challenge state that all numbers from 0-10000 must be printed? I'm pretty sure this prints numbers 0-7000 – Embodiment of Ignorance – 2019-02-04T04:34:44.200

I believe the largest valid number is 6789? This is less than 7000, so you don't have to go any higher. – dana – 2019-02-04T04:47:10.457

Oh, I see. Foolish me – Embodiment of Ignorance – 2019-02-04T04:51:59.200

Not foolish at all :) I'm pretty sure I borrowed it from someone else's answer and I was scratching my head as to why they did it. – dana – 2019-02-04T05:02:46.810

2

C (gcc), 97 89 81 bytes

Thanks to ceilingcat for -8 bytes.

Another -8 thanks to Dennis

g(n){n=!n||n/10%10<n%10&&g(n/10);}f(i){for(i=-1;++i<7e3;g(i)&&printf("%u\n",i));}

Try it online!

gastropner

Posted 2018-11-16T19:08:58.283

Reputation: 3 264

81 bytes – Dennis – 2018-11-27T13:22:38.287

not gonna update this? – ASCII-only – 2019-03-11T01:53:48.113

@ASCII-only Done. Sorry if this oversight upset you. – gastropner – 2019-03-11T02:51:23.773

1

Python 2, 63 bytes

for i in range(6790):
 if`i`=="".join(sorted(set(`i`))):print i

Try it online!

James

Posted 2018-11-16T19:08:58.283

Reputation: 54 537

1

T-SQL, 188 185 bytes

WITH a AS(SELECT 0n UNION ALL SELECT n+1FROM a WHERE n<9)
SELECT CONCAT(a.n,b.n,c.n,d.n)+0
FROM a,a b,a c,a d
WHERE(a.n<b.n OR a.n+b.n=0)
AND(b.n<c.n OR b.n+c.n=0)
AND(c.n<d.n OR c.n+d.n=0)

Line breaks are for readability only.

I'm certain there must be more efficient ways to do this in SQL, but this was the first thing I thought of. Explanation:

  1. Declare an in-memory table with values 0 to 9
  2. Cross-join 4 copies of this table for all possible values from 0000 to 9999
  3. Messy WHERE clause to ensure the digits are strictly increasing (or both 0)
  4. Smash the digits together (CONCAT) and convert to integer (+0)
  5. The resulting rows may or may not be sorted, but the challenge doesn't appear to require that.

BradC

Posted 2018-11-16T19:08:58.283

Reputation: 6 099

1You can convert to number by adding zero x+0 instead of abs(x). – Dr Y Wit – 2018-11-26T17:55:41.203

Thanks, @DrYWit, saved 3 bytes. Looks like x*1 works as well. – BradC – 2018-11-26T18:27:26.893

1

Stax, 8 bytes

¬ ▬A♥¶N∙

Run and debug it

recursive

Posted 2018-11-16T19:08:58.283

Reputation: 8 616

1

MATLAB, 52 bytes

arrayfun(@(n)disp(n(all(diff(num2str(n))>0))),0:1e4)

Luis Mendo

Posted 2018-11-16T19:08:58.283

Reputation: 87 464

1

Clean, 90 bytes

import StdEnv
Start=(0,[('
',n)\\n<-[1..6^5]|(\l=removeDup l==sort l)[c\\c<-:toString n]])

Try it online!

Οurous

Posted 2018-11-16T19:08:58.283

Reputation: 7 916

1

Red, 59 bytes

repeat n 9999[if(d: n - 1)= do sort unique form d[print d]]

Try it online!

Galen Ivanov

Posted 2018-11-16T19:08:58.283

Reputation: 13 815

1

Jelly, 7 bytes

<ƝẠ$⁹#Y

Try it online!

How?

<ƝẠ$⁹#Y - Main Link: no arguments (implicit z=0)
    ⁹   - literal 256
     #  - count up from n=z (0) finding the first 256 for which this is truthy:
   $    -   last two links as a monad:
 Ɲ      -     neighbours (implicitly gets digits of n):
<       -       less than?
  Ạ     -     all truthy? (N.B. yields 1 for an empty list)
      Y - join with newlines

Jonathan Allan

Posted 2018-11-16T19:08:58.283

Reputation: 67 804

1

Ruby, 39 bytes

puts (?0..?9*4).grep /^#{[*0..9]*??}?$/

Try it online!

G B

Posted 2018-11-16T19:08:58.283

Reputation: 11 099

1

JavaScript, 83 bytes

Borrowed some ideas from @Shaggy, but without recursion.

[...Array(1e4)].reduce((s,_,n)=>s+=([...n+''].every(x=>y<(y=x),y=0))?'\n'+n:'','0')

Try it online!

Alvin Li

Posted 2018-11-16T19:08:58.283

Reputation: 41

1

MathGolf, 10 bytes

♫rgÆ▒_s▀=n

Try it online!

Explanation

♫            push 10000
 r           range(0, n)
  g          pop a, (b), pop operator from code, filter
   Æ         start block of length 5
    ▒        split to list of chars/digits
     _       duplicate TOS
      s      sort(array)
       ▀     unique elements of string/list
        =    pop(a, b), push(a==b)
         n   newline char, or map array with newlines

maxb

Posted 2018-11-16T19:08:58.283

Reputation: 5 754

1

Brachylog, 12 bytes

7jj⟦{ẹ<₁cẉ}ˢ

Try it online!

         ẉ      Write on its own line
    {     }ˢ    every
        c       concatenated
      <₁        strictly increasing
     ẹ          list of digits of
   ⟦            numbers from the range from 0 to
7jj             7777.

7jj⟦{ṫ⊆Ị&ẉ}ˢ also works.

Unrelated String

Posted 2018-11-16T19:08:58.283

Reputation: 5 300

0

Retina 0.8.2, 38 bytes


9999$*
.
$.`¶
.
$*_$&
A`(_*)\d\1\d
_

Try it online! Explanation:


9999$*

Insert 9999 characters.

.
$.`¶

Convert into a list of numbers 0..9998

.
$*_$&

Prefix each digit with its value in _s.

A`(_*)\d\1\d

Delete lines containing nonincreasing digits.

_

Remove the now unnecessary _s.

Neil

Posted 2018-11-16T19:08:58.283

Reputation: 95 035

0

Pyth, 15 bytes

jf.A<V`Tt`TU^T4

Try it here!

Erik the Outgolfer

Posted 2018-11-16T19:08:58.283

Reputation: 38 134

0

Bash + GNU Core Utilities, 57 bytes

seq 1e4|grep -vP `seq 0 9|sed 's/./(&[0-&])/'|tr '
' \|`p

Uses some meta-regex-generation shit

markasoftware

Posted 2018-11-16T19:08:58.283

Reputation: 346

Your output is missing the 0. – Dennis – 2018-11-18T03:07:52.157

47 bytes – Dennis – 2018-11-18T03:21:51.633

0

K4, 19 bytes

Solution:

-1@$&&/'>':'$!9999;

Explanation:

-1@$&&/'>':'$!9999; / the solution
             !9999  / range 0..9998
            $       / string
        >':'        / greater-than (>) each-previous (':) each (')
     &/'            / max (&) over (/)
    &               / indices where true
   $                / string
  @                 / apply
-1                ; / print to stdout and swallow return value (-1)

streetster

Posted 2018-11-16T19:08:58.283

Reputation: 3 635

0

Kotlin, 132 131 bytes

Edit: -1 Byte thanks to @Giuseppe

fun main(){(0..9999).forEach{it.toString().let{var b=1;it.forEachIndexed{i,c->if(i>0&&it[i-1]<c)b++};if(b==it.length)println(it)}}}

Try it online!

Kromzem

Posted 2018-11-16T19:08:58.283

Reputation: 31

1I don't know Kotlin, but a trivial golf is replacing 10000 with 9999 – Giuseppe – 2018-11-26T17:35:47.080

alternative 131 – ASCII-only – 2019-03-11T01:44:37.000

96 – ASCII-only – 2019-03-11T01:49:48.703

95 – ASCII-only – 2019-03-11T02:59:41.447

0

Oracle SQL, 163 bytes

Various ways to generate combinations

with a(n)as(select level-1 from dual connect by level<11),r(i,x,s)as(select 1,n,n||''from a union all select i+1,n,s||n from r,a where(x<n or n+x=0)and i<4)select s+0 from r where i=4;

with a(n)as(select level-1 from dual connect by level<11)select a.n||b.n||c.n||d.n+0 from a,a b,a c,a d where(a.n<b.n or a.n+b.n=0)and(b.n<c.n or b.n+c.n=0)and(c.n<d.n or c.n+d.n=0);

with a(n)as(select level from dual connect by level<11)select unique replace(sys_connect_by_path(n-1,'#'),'#')+0 from(a)connect by level<5and prior n<n order by 1;
  1. Rec with (CTE), 184 bytes
  2. Self joins, 182 bytes
  3. Connect by, 163 bytes

Just for fun

with t(c)as(select ku$_vcnt(1,2,3,4,5,6,7,8,9) from dual)
select listagg(value(z)) within group (order by 0) + 0 n
  from (select rownum r, value(r) v
          from t, table(powermultiset(c)) r),
       table(v) z
 where cardinality(v) < 5
group by r union select 0 from dual

.

with a(n)as(select decode(level,10,null,level) from dual connect by level<11)
select nvl(a.n || b.n || c.n || d.n + 0, 0) n
  from a, a b, a c, a d
 where nvl2(b.n, sign(b.n - a.n), 1) = 1
   and nvl2(c.n, sign(c.n - b.n), 1) = 1
   and nvl2(d.n, sign(d.n - c.n), 1) = 1
 order by 1

Dr Y Wit

Posted 2018-11-16T19:08:58.283

Reputation: 511

0

PHP, 51 bytes

while($n<1e4)count_chars($n,3)-$n++||print~-$n."
";

Run with -nr or try it online.


count_chars($string,$mode=3) returns a string of all used characters in ascending order.
This equals the input if, and only if, its characters (in this case: digits) are strictly increasing.

$n is NULL in the first iteration; count_chars returns an empty string; NULL-"" is evaluated as 0-0.

Titus

Posted 2018-11-16T19:08:58.283

Reputation: 13 814

0

Tcl, 116 bytes

set i 0
time {set m -1;lmap n [split $i ""] {if $n>$m {set m $n} {set m X;break}}
if \$m!="X" {puts $i}
incr i} 9999

Try it online!

sergiol

Posted 2018-11-16T19:08:58.283

Reputation: 3 055

0

APL (Dyalog Extended), 28 bytes

{(⍵≡∪⍵)∧⍵≡∧⍵:⎕←⍵⋄⍬}∘⍕¨⍳10000

Try it online!

Explanation:

{(⍵≡∪⍵)∧⍵≡∧⍵:⎕←⍵⋄⍬}∘⍕¨⍳10000 ⍝ Full program
                          ⍳10000 ⍝ Generate integers from 1 to 10000
                      ∘⍕¨       ⍝ For each number, convert to string and apply left function
         ⍵≡∧⍵                   ⍝ If the string equals itself sorted...
 (⍵≡∪⍵)∧                        ⍝ ...and the string contains only unique elements...
               ⎕←⍵              ⍝ ...print the string to output with trailing newline
                   ⋄⍬            ⍝ Otherwise, do nothing

voidhawk

Posted 2018-11-16T19:08:58.283

Reputation: 1 796

1↑c/⍨(,⍨≡∧,∪)¨c←⍕¨⍳1E4 – Adám – 2019-03-11T05:39:30.987

0

C++ (gcc), 113 bytes

bool y(int a){return(a==0||a%10>(a/=10)%10&&y(a))?true:false;}void z(int i){while(++i<7e3)if(y(i))cout<<i<<endl;}

Try it online!

Pretty Layout:

#include<iostream>
using namespace std;

bool y(int a){
    return(a==0||a%10>(a/=10)%10&&y(a))?true:false;
}

void z(int i){
    while(++i<7e3){
        !y(i)?:cout<<i<<endl;
    }
}

int main(){
    z(-1);
}

X1M4L

Posted 2018-11-16T19:08:58.283

Reputation: 1 586

97 bytes – ceilingcat – 2019-04-18T01:10:03.180

0

Java 8

Full program: 186 bytes

interface M{static void main(String[]a){for(int i=-1;i++<9999;System.out.print((i+"").chars().distinct().sorted().mapToObj(c->(c-48)+"").reduce("",(x,y)->x+y).equals(i+"")?i+"\n":""));}}

Function: 149 bytes

v->{for(int i=-1;i++<9999;System.out.print((i+"").chars().distinct().sorted().mapToObj(c->(c-48)+"").reduce("",(x,y)->x+y).equals(i+"")?i+"\n":""));}

Benjamin Urquhart

Posted 2018-11-16T19:08:58.283

Reputation: 1 262

0

Burlesque, 11 bytes

1e4qsoFO:U_

Equivalently

1e4ro:so:U_

Try it online!

1e4 # 10000
qso # Boxed is sorted?
FO  # Filter from 1..10000 if sorted
:U_ # Filter for unique digits

DeathIncarnate

Posted 2018-11-16T19:08:58.283

Reputation: 916