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

R, 27 bytes

(Or 20 bytes in R>=4.1 using \ instead of function)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s sample function is prob=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a “convenience” feature of sample changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using \ instead of function)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using \ instead of function)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using \ instead of function)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s sample function is prob=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a “convenience” feature of sample changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using \ instead of function)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using \ instead of function)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using \ instead of function)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s sample function is prob=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a “convenience” feature of sample changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using \ instead of function)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

Formatting change
Source Link
pajonk
  • 18.3k
  • 3
  • 26
  • 74

R, 27 bytes

(Or 20 bytes in R>=4.1 using ‘\’\ instead of ‘function’function)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s ‘sample’sample function is ‘prob’=“aprob=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a ‘convenience’“convenience” feature of ‘sample’sample changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using ‘\’\ instead of ‘function’function)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’\ instead of ‘function’function)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s ‘sample’ function is ‘prob’=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a ‘convenience’ feature of ‘sample’ changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using \ instead of function)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s sample function is prob=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a “convenience” feature of sample changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using \ instead of function)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using \ instead of function)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

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

R, 27 bytes

(Or 20 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s ‘sample’ function is ‘prob’=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a ‘convenience’ feature of ‘sample’ changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 2931 bytes

(Or 2224 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)max(-sample(-x,2,T))

Try it online!Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s ‘sample’ function is ‘prob’=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a ‘convenience’ feature of ‘sample’ changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)max(-sample(-x,2))

Try it online!

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

R, 27 bytes

(Or 20 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)-sample(-x,1,,x)

Try it online!

The 4th argument of R’s ‘sample’ function is ‘prob’=“a vector of probability weights for obtaining the elements of the vector being sampled”.

Unfortunately, a ‘convenience’ feature of ‘sample’ changes its behaviour when its first argument is a single positive number, so we need to negate it here to avoid this, and then re-negate the result.

——

R, 31 bytes

(Or 24 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)max(-sample(-x,2,T))

Try it online!

Return the highest of two random picks.

——

R, 29 bytes

(Or 22 bytes in R>=4.1 using ‘\’ instead of ‘function’)

function(x)sample(rep(x,x),1)

Try it online!

Only valid for integer input.

added 13 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
deleted 69 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
deleted 13 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 379 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
typo
Source Link
noodle person
  • 10.3k
  • 1
  • 22
  • 76
Loading
added 563 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
added 145 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60
Loading