Recovering Range Parameters
Octave, 82 bytes
function y=f(x)
while any(floor(y=linspace(x(1)+rand,x(end)+rand,numel(x)))-x),end
Running time is non-deterministic, but the code ends in finite time with probability 1.
Try it online!
Explanation
The code defines a function
of x
that outputs y
. The function consists of a while
loop.
In each iteration, the right amount (numel(x)
) of linearly spaced values are generated (linspace
), starting at x(1)+rand
and ending at x(end)+rand
. These two calls to the rand
function give random offsets between 0
and 1
, which are applied to the initial and final values of x
.
The loop is repeated for as long as any
of the floor
ed results differs (-
) from the corresponding entry in x
.
Python 3, 189 bytes
def f(l):
R=range(len(l));e=1-1e-9
for j in R:
for I in range(j*4):
i=I//4;L=[((l[i]+I//2%2*e)*(x-j)-(l[j]+I%2*e)*(x-i))/(i-j)for x in R]
if[x//1 for x in L]==l:return L
return l
Try it online!
Cubic time.
Has some numerical issues.
R, 86 bytes
function(n){while(any(n-(x=seq(n[1]+runif(1),tail(n,1)+runif(1),l=sum(n|1)))%/%1))0;x}
Try it online!
R port of Luis Mendo's answer; it does issue a number of warnings because of any
coercing to logical
but these can be ignored.