Skip to main content
added 322 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 3223 bytes

Edit: -9 bytes thanks to Command Master by switching to use a bitmask as input

function(h,n)rank(1:n%in%hh,,"f")

Try it online!Try it online!

Input is simply a bitmask 1:n %in% h returns a vector of mainly zeros, with ones whereno need to provide n as this is implicitly the high-water marks should belength of the bitmask. 
The "f" (short for ties="first") argument to rank() indicates that ties with the same rank should be broken using "increasing values at each index set of ties".


Old approach: R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

R, 32 bytes

function(h,n){x=1:n;x[h]=-x;rankrank(-x1:n%in%h,,"f")}

Try it online!Try it online!

Same approach as above, except inputting h as the indices of high-water marks, together with n. 1:n %in% h returns a vector of mainly zeros, with ones where the high-water marks should be (in other words, converting the indices to a bitmask).

R, 32 bytes

function(h,n)rank(1:n%in%h,,"f")

Try it online!

1:n %in% h returns a vector of mainly zeros, with ones where the high-water marks should be. The "f" (short for ties="first") argument to rank() indicates that ties with the same rank should be broken using "increasing values at each index set of ties".


Old approach: R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=1:n;x[h]=-x;rank(-x)}

Try it online!

R, 23 bytes

Edit: -9 bytes thanks to Command Master by switching to use a bitmask as input

function(h)rank(h,,"f")

Try it online!

Input is simply a bitmask h, no need to provide n as this is implicitly the length of the bitmask. 
The "f" (short for ties="first") argument to rank() indicates that ties with the same rank should be broken using "increasing values at each index set of ties".

R, 32 bytes

function(h,n)rank(1:n%in%h,,"f")

Try it online!

Same approach as above, except inputting h as the indices of high-water marks, together with n. 1:n %in% h returns a vector of mainly zeros, with ones where the high-water marks should be (in other words, converting the indices to a bitmask).

added 619 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 40 3732 bytes

function(h,n)rank(1:n%in%h,,"f")

Try it online!

1:n %in% h returns a vector of mainly zeros, with ones where the high-water marks should be. The "f" (short for ties="first") argument to rank() indicates that ties with the same rank should be broken using "increasing values at each index set of ties".


Old approach: R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=1:n;x[h]=-x;rank(-x)}

Try it online!

R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=1:n;x[h]=-x;rank(-x)}

Try it online!

R, 32 bytes

function(h,n)rank(1:n%in%h,,"f")

Try it online!

1:n %in% h returns a vector of mainly zeros, with ones where the high-water marks should be. The "f" (short for ties="first") argument to rank() indicates that ties with the same rank should be broken using "increasing values at each index set of ties".


Old approach: R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=1:n;x[h]=-x;rank(-x)}

Try it online!

added 63 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 4040 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=-(1:n);x[h]=1x=1:n;rankn;x[h]=-x;rank(-x)}

Try it online!Try it online!

R, 40 bytes

function(h,n){x=-(1:n);x[h]=1:n;rank(x)}

Try it online!

R, 40 37 bytes

Edit: -2 bytes thanks to Command Master & Giuseppe

function(h,n){x=1:n;x[h]=-x;rank(-x)}

Try it online!

Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading