Implement Lazy Drop Sort

26

2

This challenge already describes dropsort. However, I'm kinda lazy and I really only need my array to be a bit more sorted than before, it doesn't need to be sorted all the way.

In Drop Sort, we drop every element less than any element before it. In Lazy Drop Sort, we drop every element less than the one strictly preceding it.

Here's an example. Consider the following array:

8 6 9 9 7 2 3 8 1 3

Let's mark every element less than the one before it.

8 6 9 9 7 2 3 8 1 3
  ^     ^ ^     ^

Notice how neither 3 was marked, nor the last 8. They are all larger than the single element to the left of them.

Completing the algorithm, removing the marked elements, we get:

8 9 9 3 8 3

That basically looks more sorted. Kinda. I'm lazy.

Your task, as you may have already deduced, is to implement this algorithm.

Input is an array of at least 1 positive integer between 1 and 9, so you can take a string of digits as well.

This is , fewest bytes wins!

Additional test cases:

1
1

1 2 3
1 2 3

5 3 1
5

1 2 3 2 1
1 2 3

1 1 1 9 9 9 1 1 1 9 9 9 1 1 1
1 1 1 9 9 9 1 1 9 9 9 1 1

9 9
9 9

5 2 4 2 3
5 4 3

Pavel

Posted 2018-03-22T15:27:57.710

Reputation: 8 585

Can it be a function or it must be a complete program? – rafa11111 – 2018-03-23T00:40:11.253

@rafa11111 Either is fine – Pavel – 2018-03-23T00:44:27.107

In the case it is a function, can the input array be hardcoded in the main program? And can the length of the array be passed as input to the function? – rafa11111 – 2018-03-23T01:56:26.380

@rafa11111 The input can't be hardcoded in the function itself. It doens't matter how the function gets this input in your test program. You can take an array length only if you're using C/C++ or another language where that's the only way to determine an array's length. – Pavel – 2018-03-23T02:08:31.053

Answers

6

Husk, 4 bytes

m←ġ<

Try it online!

Explanation

m←ġ<
  ġ<    Group the numbers into decreasing sequences
m←      Keep the first element of each sequence

Leo

Posted 2018-03-22T15:27:57.710

Reputation: 8 482

15

JavaScript (ES6), 28 25 bytes

Saved 3 bytes thanks to @Shaggy

a=>a.filter(n=>~-a<(a=n))

Try it online!

Arnauld

Posted 2018-03-22T15:27:57.710

Reputation: 111 334

2n=>p<=n would have looked awesome ;-) – ETHproductions – 2018-03-22T15:49:30.357

4@ETHproductions For +4 bytes, (n=p)=>p<=(p=n) works fine ;) – Arnauld – 2018-03-22T15:52:14.990

this answer is blowing my mind, why doesn't this explode when trying to access p for the first time, when it's not defined yet? – Brian H. – 2018-03-22T16:26:29.090

@BrianH. p=0 is a evaluated as a (meaningless) parameter of map() before the loop begins. So p is actually initialized. – Arnauld – 2018-03-22T17:17:25.107

@BrianH. And of course I meant a parameter of filter() O_o – Arnauld – 2018-03-22T17:40:58.903

Would a=>a.filter(n=>~~a<=(a=n)) work for 26 bytes? – Shaggy – 2018-03-22T17:42:30.903

1@Shaggy That looks safe. Will update when I'm back in front of a computer. Thanks! – Arnauld – 2018-03-22T17:44:29.653

Why ~-a and not just a-1? – Pavel – 2018-03-22T19:46:10.843

2@Pavel a is initially set to the input array and a-1 would result in NaN (unless it contains a single integer, in which case it is coerced to this integer). – Arnauld – 2018-03-22T19:51:25.137

6

R, 27 bytes

(l=scan())[c(T,diff(l)>=0)]

Try it online!

Giuseppe

Posted 2018-03-22T15:27:57.710

Reputation: 21 077

6

MATL, 9 8 bytes

Saved one byte thanks to Giuseppe.

0yd0<h~)

Try it online!


Explanation:

0                 % Push a zero
 y                % Implicitly grab the input and duplicate it.
                  % Stack: [8 6 9 9 7 2 3 8 1 3], 0, [8 6 9 9 7 2 3 8 1 3]
  d               % The difference between each number of the last element:
                  % Stack: [8 6 9 9 7 2 3 8 1 3], 0, [-2, 3, 0, -2, -5, 1, 5, -7, 2]
   0<             % Which are negative?
                  % Stack: [8 6 9 9 7 2 3 8 1 3], 0, [1 0 0 1 1 0 0 1 0]
     h            % Concatenate. Stack: [8 6 9 9 7 2 3 8 1 3], [0 1 0 0 1 1 0 0 1 0] 
      ~           % Negate. Stack: [8 6 9 9 7 2 3 8 1 3], [1 0 1 1 0 0 1 1 0 1]
       )          % Index. Stack: [8 9 9 3 8 3]

Stewie Griffin

Posted 2018-03-22T15:27:57.710

Reputation: 43 471

5

Perl 5.10.0 + -nl, 16 bytes

$f>$_||say;$f=$_

Try it online!

wastl

Posted 2018-03-22T15:27:57.710

Reputation: 3 089

1Translation to Perl 6 perl6 -ne '$/>$_||.say;$/=$_' – Brad Gilbert b2gills – 2018-03-22T22:46:56.243

@Brad perl6 is a different language (it's not even backwards-compatible) Post it! – wastl – 2018-03-23T05:44:38.100

I wrote one that was more idiomatic Perl 6, but it was longer. Also one of the reasons I post here is to show off the language, and to explain it. Posting that translation does nothing but show that it is a slightly more verbose version of Perl. Basically it satisfies none of the reasons why I post on this site. – Brad Gilbert b2gills – 2018-03-24T15:58:13.720

5

Haskell, 29 bytes

f s=[b|(a,b)<-zip(0:s)s,a<=b]

just a simple list comprehension.

proud haskeller

Posted 2018-03-22T15:27:57.710

Reputation: 5 866

4

Japt, 8 7 bytes

Saved 1 byte thanks to @Oliver

k@>(U=X

Test it online!

Alternatives:

f@T§(T=X
k@ä>0 gY
i0 ò> mÅ c

ETHproductions

Posted 2018-03-22T15:27:57.710

Reputation: 47 880

Came up with the exact same solution :) – Shaggy – 2018-03-22T17:39:49.820

4

Java 8, 66 55 48 bytes

l->{for(int i=0;;)if(i>(i=l.next()))l.remove();}

-11 bytes after a tip from @OlivierGrégoire.
-7 more bytes thanks to @OlivierGrégoire.

Explanation:

Try it online.

l->{                     // Method with Integer-ListIterator parameter and no return-type
  for(int i=0;;)         //  Loop over all items
    if(i>(i=l.next()))   //   If the current item is larger than the next
      l.remove();}       //    Remove this next item

Kevin Cruijssen

Posted 2018-03-22T15:27:57.710

Reputation: 67 575

Why does everyone start using ~0 when it's basically -1. Personally I would choose the more intuitive solution if the byte-count is the same length (except for while(...) vs for(;...;), in which case I prefer the for. Thanks for another -7 bytes, though. :) – Kevin Cruijssen – 2018-03-22T18:21:23.450

It's because I'm bad with 2-complement... I'm so bad I wanted to mean Integer.MIN_VALUE (which is then 1<<31, I guess...) ;-) – Olivier Grégoire – 2018-03-22T18:32:46.793

4

Stax, 5 bytes

âÿ╠╦░

Run and debug this online

Unpacking, ungolfing, and commenting the code, we get this.

Z   Push a zero under the input
f   Use the rest of the program as a filter on the input.  Output passing elements.
>   Current element is greater than previous?
_~  Push current element to the input stack; when the main stack is empty, pops fall back to this
!   Logical not; applies to the result of the greater-than

Run this one

The ordering of the instructions is awkward but there's a reason for it. Stax source code packing doesn't always yield the same size output for the same size input. Basically, you have a chance to save a byte if the last character of source has a lower character code. Well, ! has one of the lowest codes you can get for a printable character. (33 specifically) Many 6 byte ASCII stax programs can't pack any smaller. But if they end with a !, then they can. So the reason for this particular ordering of instructions is to ensure that the logical not ends up at the end of the program.

recursive

Posted 2018-03-22T15:27:57.710

Reputation: 8 616

4

J, 12 Bytes

#~1,2&(<:/\)

Explanation:

#~1,2&(<:/\)    | Whole function, executed as a hook
       <:/      | Distribute <: (greater or equal) over an array
    2&(   \)    | Apply to each sub array of length 2
  1,            | Append a 1 to the front
#~              | Choose elements from the original array

Examples:

    2&(<:/\) 8 6 9 9 7 2 3 8 1 3
0 1 1 0 0 1 1 0 1
    1,2&(<:/\) 8 6 9 9 7 2 3 8 1 3
1 0 1 1 0 0 1 1 0 1
    (1 0 1 1 0 0 1 1 0 1) # 8 6 9 9 7 2 3 8 1 3
8 9 9 3 8 3
    f =: #~1,2&(<:/\)
    f 8 6 9 9 7 2 3 8 1 3
8 9 9 3 8 3

Try it online!

Bolce Bussiere

Posted 2018-03-22T15:27:57.710

Reputation: 970

Nice solution! I added a TIO link for your code. – Galen Ivanov – 2018-03-22T18:10:37.317

4

Jelly, 6 bytes

>Ɲ0;¬×

I/O is on strings.

Try it online!

Dennis

Posted 2018-03-22T15:27:57.710

Reputation: 196 637

I'm curious, why operate on strings and not arrays? I was told Jelly is bad at strings. – Pavel – 2018-03-22T19:01:12.093

2It is. × shouldn't work for character repetition, but it does. – Dennis – 2018-03-22T19:07:45.170

4

Octave, 21 bytes

@(x)x(~[0,diff(x)<0])

Try it online!

Explanation:

Take a vector x as input, and create a vector [0, diff(x)<0], where diff(x) is a vector with the difference between all adjacent elements. Keep only those that are negative by comparing it to zero, giving us a list of all the elements we want to drop.

We then select the elements from the input vector that we want to keep.

Stewie Griffin

Posted 2018-03-22T15:27:57.710

Reputation: 43 471

4

V, 25 bytes

òjälá k$yl+@"òç-/d
ç /dw

Try it online!

Hexdump:

00000000: f26a e46c e120 6b24 796c 2b40 2218 f2e7  .j.l. k$yl+@"...
00000010: 2d2f 640a e720 2f64 77                   -/d.. /dw

Worst language for the job. But I did it for a dare.

James

Posted 2018-03-22T15:27:57.710

Reputation: 54 537

6Side note: ojalá is Spanish for hopefully. – Dennis – 2018-03-22T21:45:15.097

2@dennis That's cool. What is k$yl+@"òç-/d Spanish for? – James – 2018-03-22T21:57:56.190

7k$yl+@"òç-/d might be liberally translated as Ouch, who the hell left that cupboard door open? – Luis Mendo – 2018-03-22T22:32:50.820

3

Python 2, 52 46 45 42 bytes

lambda a:[v for v,w in zip(a,[1]+a)if v/w]

Try it online!


Saved:

  • -3 bytes, thanks to Rod

TFeld

Posted 2018-03-22T15:27:57.710

Reputation: 19 246

3

Triangularity, 71 bytes

.....).....
....IEL....
...)rFD)...
..2+)IE)w..
.+h)2_stDO.
={M)IEm}...

Try it online!

How it works?

)IEL)rFD)2+)IE)w+h)2_stDO={M)IEm} – Full program.
)IE                               – Get the 0th input I and evaluate it.
   L)r                            – And push the range [0 ... length of I).
      F                   {       – Filter the integers in this range which satisfy:
       D)2+)IE)w+h)2_stDO=        – This condition. Runs each element E on a separate
                                    stack and discard those that don't meet the criteria.
       D)2+                       – Duplicate and add 2 to the second copy.
           )IE                    – Retrieve I again.
              )                   – Push a 0 onto the stack.
               w                  – Wrap the 0 in a list. [0]
                +                 – Prepend it to I.
                 h                – Head. Trim the elements after index E+2.
                  )2_             – Literal -2.
                     st           – Tail.
                       DO=        – Check whether the result is invariant over sorting.
                           M)IEm} – Last part: indexing into the input.
                           M    } – For each index that satisfies the conditions:
                            )IEm  – Retrieve the element of I at that position.

Mr. Xcoder

Posted 2018-03-22T15:27:57.710

Reputation: 39 774

2Out of curiosity (since you are the creator of Triangularity): why not do something similar as Hexagony / Cubically, where a piece of code is automatically filled with the no-op dots? So this program would be )IEL)rFD)2+)IE)w+h)2_stDO={M)IEm} which would expand to your current answer? – Kevin Cruijssen – 2018-03-22T16:20:42.620

@KevinCruijssen Because I was actually planning to make Triangularity a 2D esolang, but I gave up on the idea so I just sticked to my previous template. I think I'll make some major changes soon, when I release Triangularity v2. (Also it's kinda fun to golf in it in its current form, because a simple 1-byte save inline might instead save you 20 :D... It also applies retroactively when fixing stuff though :C) – Mr. Xcoder – 2018-03-22T16:25:13.830

Well, even if you do plan on releasing it as a 2D esolang, my comment still stands (somewhat). )IEL)rFD)2+)IE)w+h)2_stDO={M)IEm} would be your code, it would expand to your current template, and then do the 2D commands on that expanded template. EDIT: .....).....\n....IEL....\n...)rFD)...\n..2+)IE)w..\n.+h)2_stDO.\n={M)IEm}... and .....).........IEL.......)rFD).....2+)IE)w...+h)2_stDO.={M)IEm}... and )IEL)rFD)2+)IE)w+h)2_stDO={M)IEm} would all three be the exact same program. – Kevin Cruijssen – 2018-03-22T16:28:30.843

3

Wonder, 27 bytes

-> ':1.!> 'sS#<=.cns2.++[0]

Usage example:

(-> ':1.!> 'sS#<=.cns2.++[0])[8 6 9 9 7 2 3 8 1 3]

Explanation

Ungolfed version:

(map get 1).(fltr sS <=).(cns 2).(++ [0])

Prepend 0, get list of consecutive pairs, keep list items where first number <= second number, get second number of each pair.

Mama Fun Roll

Posted 2018-03-22T15:27:57.710

Reputation: 7 234

3

Python, 40 bytes

f=lambda h,*t:t and h+f(*t)[h>t[0]:]or h

Try it online!

Input as tuple of characters.


Python 3, 41 bytes

p=''
for x in input():x<p or print(x);p=x

Try it online!

String input.


Python 2, 41 bytes

for x in input():
 if x>=id:print x
 id=x

Try it online!

String input, just because strings are greater than id but numbers are smaller.

xnor

Posted 2018-03-22T15:27:57.710

Reputation: 115 687

3

Wolfram Language (Mathematica), 33 bytes

Pick[#,Arg[#-{0}~Join~Most@#],0]&

Try it online!

How it works

The code # - {0}~Join~Most@# turns an array {a,b,c,d,e,f} into {a,b-a,c-b,d-c,e-d,f-e}. Applying Arg to this sets negative numbers to Pi and nonnegative numbers to 0.

Pick[#, ..., 0]& picks out the entries of # where ... has a 0: in our case, exactly the elements that yield a nonnegative number when you subtract the previous element. In other words, these are exactly the entries we want to keep when lazydropsorting.

Misha Lavrov

Posted 2018-03-22T15:27:57.710

Reputation: 4 846

3

Wolfram Language (Mathematica), 20 bytes

#&@@@Split[#,##>0&]&
(* or *)
Max/@Split[#,##>0&]&

Try it online!

Explanation

Input = {8, 6, 9, 9, 7, 2, 3, 8, 1, 3}

Split[#,##>0&]

Group consecutive elements that are strictly decresasing: {{8, 6}, {9}, {9, 7, 2}, {3}, {8, 1}, {3}}

#&@@@

Take the first element of each: {8, 9, 9, 3, 8, 3}

JungHwan Min

Posted 2018-03-22T15:27:57.710

Reputation: 13 290

##>0 is fancy and everything, but it doesn't really save anything over #>#2 here ;) (which would make your program work with arbitrary integers, not that that's required though). – Martin Ender – 2018-03-25T21:49:47.257

3

SWI-Prolog, 44 bytes

[A,B|C]-[A|E]:-B<A,[B|C]-[B|E];[B|C]-E. L-L.

Usage: Call "List-X" where List is a bracket-enclosed, comma-separated list e.g. [1,4,5,1,11,6,7].

ashtraypettingzoo

Posted 2018-03-22T15:27:57.710

Reputation: 51

1Welcome to the site! :) – James – 2018-03-28T12:56:32.157

2

APL+WIN, 14 bytes

Prompts for screen input of a vector of integers.

(1,1>2-/v)/v←⎕

Graham

Posted 2018-03-22T15:27:57.710

Reputation: 3 184

2

05AB1E, 6 bytes

ĆÁü›_Ï

Try it online!

Explanation

Ć        # append the head of the list
 Á       # rotate right
  ü›     # apply pair-wise greater-than
    _    # logical negate each
     Ï   # keep elements of input that are true in this list

Emigna

Posted 2018-03-22T15:27:57.710

Reputation: 50 798

2

C# (.NET Core), 33 + 18 = 51bytes

x=>x.Where((a,n)=>n<1||x[n-1]<=a)

Try it online!

basically the statement is where x is the first int in the array, or is greater than or equal to the previous number, keep it. Else drop it.

Dennis.Verweij

Posted 2018-03-22T15:27:57.710

Reputation: 101

1You can return an IEnumerable. No ToArray() needed. – Pavel – 2018-03-22T17:21:04.790

@Pavel I would need to add an extra reference System.Collections, and that would negate all the bytes saved for removing the ToArray(). – Dennis.Verweij – 2018-03-22T22:12:16.537

No, since you won't be referencing IEnumerable in the answer, just using it as the return type. – Pavel – 2018-03-22T22:27:54.450

@Pavel okay thanks, sometimes I'm a bit unsure when to count the bytes or not... sorry – Dennis.Verweij – 2018-03-23T07:39:32.813

2

Kotlin, 39 bytes

a->a.filterIndexed{i,v->i<1||v>=a[i-1]}

Try it online!

Filter items that are either the first item (index==0, or even shorter index<1) OR the current Value is greater than or equal to the previous item (a[i-1]).

Makotosan

Posted 2018-03-22T15:27:57.710

Reputation: 503

2

APL (Dyalog Unicode), 11 bytes

{⍵⌿⍨1⍪2≤⌿⍵}

Try it online!

This is actually pretty similar to Graham's answer, but in Dyalog, and independently developed. Also, more symmetric.

Erik the Outgolfer

Posted 2018-03-22T15:27:57.710

Reputation: 38 134

2

K4, 10 bytes

Solution:

x_/|&<':x:

Example:

q)k)x_/|&<':x:8 6 9 9 7 2 3 8 1 3
8 9 9 3 8 3

Explanation:

Find indices where element is less than preceding, remove these indices from the input

x_/|&<':x: / the solution
        x: / store input as x
     <':   / less-than each-previous
    &      / indices where true
   |       / reverse
 _/        / drop-over
x          / the input

streetster

Posted 2018-03-22T15:27:57.710

Reputation: 3 635

2

Attache, 24 bytes

{Mask[1'(Delta!_>=0),_]}

Try it online!

Explanation

Mask selects all elements from its second argument which correspond to truthy elements in its first argument. 1'(Delta!_>=0) calculates the indices which correspond to elements that are supposed to be in the final array.

Other attempts

28 bytes (pointfree): ~Mask#(1&`'##Delta#`>=#C[0])

32 bytes: {Mask[1'(&`<= =>Slices[_,2]),_]}

Conor O'Brien

Posted 2018-03-22T15:27:57.710

Reputation: 36 228

1

Jelly, 9 bytes

0;>ƝżµḢÐṂ

Try it online!

This feels pretty bulky, wouldn't be that surprised if there is a better way.

0;>ƝżµḢÐṂ
   Ɲ       For each adjacent pair in the input...
  >        ...is the first element greater than the second? (yields a list of 0/1)
0;         prepend a zero to this list (always keep the first element)
    ż      zip with the input
     µ     new monadic link
       ÐṂ  keep elements of the list with minimal value of... (Ðḟ would have worked here and been slightly more clear but I'll leave it as it is)
      Ḣ    ...their first element

dylnan

Posted 2018-03-22T15:27:57.710

Reputation: 4 993

1

Swift 4, 56 55 bytes

{var l=0;print($0.filter{($0>=l,l=$0).0})}as([Int])->()

Try it online!

Explanation

{var l=0;           // Declare variable l
print($0.filter{(   // Print every element e in the input
  $0>=l,            //   where e >= l
  l=$0).0})         //   And set l to e
}as([Int])->()      // Set the input type to integer array

Herman L

Posted 2018-03-22T15:27:57.710

Reputation: 3 611

1

Brain-Flak, 136, 120 bytes

((())){{}([{}]({}))([({}<(())>)](<>)){({}())<>}{}{((<{}>))<>{}}{}<>{}{{}(({})<>)(())(<>)}{}([][()])}{}{}<>{{}({}<>)<>}<>

Here it is formatted and "readable".

((()))
{
    {}

    ([{}]({}))

    ([({}<(())>)](<>)){({}())<>}{}{((<{}>))<>{}}{}<>{}

    {
        {}(({})<>)(())(<>)
    }

    {}

    ([][()])

}{}{}<>

{
    {}
    ({}<>)<>
}<>

Try it online!

James

Posted 2018-03-22T15:27:57.710

Reputation: 54 537

1

SHELL ( 45 Bytes)

Solution 1 : output on 1 line ( 57 Bytes)

L(){ for i in $*;do(($i>=$o))&&echo $i;o=$i;done|xargs;}

Test :

>L 8 6 9 9 7 2 3 8 1 3
8 9 9 3 8 3

Solution 2 : output 1 element / line ( 51 Bytes)

L(){ for i in $*;do(($i>=$o))&&echo $i;o=$i;done;}

Test :

>L 8 6 9 9 7 2 3 8 1 3
8
9
9
3
8 

Solution 3 : with bc ( 51 Bytes)

 L(){ for i in $*;do bc<<<"if($i>$o)$i";o=$i;done;}

Solution 4 : optimisation ( suppression in $*, thanks user17752 ) ( 45 Bytes)

 L(){ for i;do bc<<<"if($i>$o)$i";o=$i;done;}

Ali ISSA

Posted 2018-03-22T15:27:57.710

Reputation: 211

I don't think you need the space after L, or xargs. – Pavel – 2018-03-22T23:22:37.273

1Also, which shell is this? I get a syntax error in Bash: – Pavel – 2018-03-22T23:31:10.960

1for i in $* can be shortened to for i – DarkHeart – 2018-03-23T06:42:56.433

1Tested on Cygwin ( CYGWIN_NT-10.0 2.3.1(0.291/5/3) ) – Ali ISSA – 2018-03-23T22:02:22.537

1

Python 2, 50 49 bytes

f=lambda s:s and f(s[:-1])+s[-1]*(s[-2:]<s[-1]*3)

I/O is on strings.

Try it online!

Dennis

Posted 2018-03-22T15:27:57.710

Reputation: 196 637

1

Retina 0.8.2, 32 31 bytes

\d
$*
r`(?<=1\1) (1+)\b

1+
$.&

Try it online! Link includes test cases. Explanation: The first and last stages are simply unary conversion. The middle stage deletes the numbers that are preceded by a larger number. A right-to-left match is used so that the lookbehind can be placed at the start of the regex, saving 1 byte.

Neil

Posted 2018-03-22T15:27:57.710

Reputation: 95 035

1

Fortran (GFortran), 74 bytes

SUBROUTINE D(I,J)
INTEGER I(J)
DO1 K=1,J
1 IF(I(K)>=I(K-1))PRINT*,I(K)
END

This is my entry in this lovely language. It simply prints the "sorted" array, doesn't return it. I is the array to be "sorted" and J is its length. The TIO link below shows a complete program (with 160 bytes) using the subroutine. The input array is hardcoded in the main program.

Actually, I think that there might be some way to get an unknown length array as input, even from STDIN, using allocatable arrays, but it would be a really ugly program. Anyway, it seems fair to be lazy while implementing a lazy algorithm in a aged (and, therefore, tired) programming language :).

Conclusion: Fortran is an awesome language for arrays, as far as you know their lengths.

Try it online!

rafa11111

Posted 2018-03-22T15:27:57.710

Reputation: 310

1

C, 82 bytes

f(a,c,i,j)int*a;{for(i=-1;++i<c;j=a[i])printf("%d "+3*(i&&j>a[i]),a[i]);puts("");}

Try it online!

I used the usual tricks (using K&R-style functions, indexing into a constant string, etc.) and because I don't like ending output on the same line as the next program added a newline. To make sure that the 1-element arrays were handled correctly, I special-cased it.

ErikF

Posted 2018-03-22T15:27:57.710

Reputation: 2 149

1

C (clang), 53 bytes

x,c;f(char *s){for(x=0;c=*s++;x=c)c>=x?putchar(c):0;}

Try it online!

Takes input as string of digits, For all digits, prints it if greater than previous.

GPS

Posted 2018-03-22T15:27:57.710

Reputation: 341

Suggest c<x||putchar(c); instead of c>=x?putchar(c):0; – ceilingcat – 2018-10-04T17:22:19.140