New answers tagged

0

SAP ABAP, 174 bytes FORM f TABLES t.DATA r TYPE int_tab1.LOOP AT t.DATA(i) = 0.DATA(x) = sy-tabix.LOOP AT t.CHECK:sy-tabix < x,t = t[ x ].i = i + 1.ENDLOOP.APPEND i TO r.ENDLOOP.t[] = r.ENDFORM. Subroutine which takes a table of integers and replaces all values with zero-based indices. ABAP has no array type, so a table of integers is the closest thing ...


1

K (ngn/k), 18 bytes (,/.!'#'=x)@<,/.=x Try it online! OLD APPROACH K (ngn/k), 27 23 22 bytes {x[,/.=x]:,/.!'#'=x;x} Try it online! this is not pretty... quick and dirty solution, i will be refining this later when i get the chance to think of a better approach explanation: =x returns a dict where keys are items of x and values are their indices (...


0

Pyth, 7 bytes .e/<Qkb Try it online! .e Q # enumerated map over (implicit) Q (input): lambda k,b: (k=index, b=element) / b # number of occurences of b in <Qk # Q[:k] Alternative 1-based solution (7 bytes) m/ded._ Try it online! m ._ # map over all prefixes of (implicit) Q (input): lambda d: / ed # Number of occurences of d[-1]...


0

Oracle SQL, 115 bytes (Version 12c+) select x from t match_recognize(order by i all rows per match pattern((p|{-y-})+)define p as x>=nvl(last(p.x,1),x)) It works with an assumption that input data is stored in a table t(i,x) (i for order), e.g. with t(i,x) as (select rownum,value(v) from table(sys.odcinumberlist(1,2,5,4,3,7))v) Test in SQL*Plus. SQL&...


1

Japt -h, 9 bytes à ñÊf_eZñ Try it


1

VBA, 173 133 bytes Sub s(c) d=UBound(c) ReDim r(d) r(i)=c(i) For i=1To d If r(j)<=c(i)Then j=j+1:r(j)=c(i) Next ReDim Preserve r(j) c=r End Sub (after edits) The above code is shorter and expects the parameter c to be passed as a variant array of numbers. My original Test_Cases sub below uses the Split() function which returns an array of strings. You ...


0

Wolfram Language (Mathematica), 37 bytes Select[Reverse@Subsets@#,OrderedQ,1]& Try it online! The elements of Subsets[ ] are ordered from shortest to longest, so reversing it puts longer subsets first. Then, select the first one which is ordered.


0

Ruby, 63 bytes ->a{s=a.size;s-=1until r=a.combination(s).find{|e|e==e.sort};r} Try it online! ->a{ # Anonymous Proc taking array input s=a.size; # Get array size until # Loop until the following condition is non-nil: r=a.combination(s) ...


0

Stax, 9 bytes éÑ<┬Θ╡Lφ0 Run and debug it Naive approach: powerset, filter for sorted, sort on length, get tail.


0

Python 2, 89 83 bytes f=lambda A:A>sorted(A)and max([f(A[:i]+A[i+1:])for i in range(len(A))],key=len)or A Try it online!


3

Jelly, 6 bytes ŒPṢƑƇṪ Try it online! How? Pretty much the same approach as Grimy's 05AB1E entry ŒPṢƑƇṪ - Link: list of integers ŒP - power-set (all subsequences, from shortest to longest) Ƈ - filter keep those which are: Ƒ - invariant when: Ṣ - sorted Ṫ - tail


1

Python 3, 58 56 bytes f=lambda x:[e for i,e in enumerate(x)if max(x[:i+1])==e] Not sure if the input would be a string or a list, my code only would work in the second case.


3

05AB1E, 8 bytes æʒD{Q}éθ Try it online! æ # list of subsequences ʒD{Q} # filter, keep only the sorted subsequences é # sort by length θ # get the last (longest) one


0

MathGolf, 10 bytes ╓\ô`╙┼=╛o╘ Try it online! This solution relies on stack manipulation. It could have been 2 bytes shorter if negative numbers are not included (skip the first two bytes). Basically a port of the 05AB1E answer, except there is more of a hassle to get the stack right. Explanation ╓ minimum of two elements, min of list, minimum ...


Top 50 recent answers are included