Skip to main content
saved 9 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7ES6), 113104 bytes

Saved 9 bytes by refactoring in a way similar to what xnor did

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N(g=q=>[x,c=X+x+~Nx+q,c-N,c,a+N]-x].map((v,i)=>v*v+[b=y=>Math.hypot(X-Y,d=Y+y+~Nv,bY-N[y,N-d,b+Ny,d][i]**2y+q][i]))**)(N++),.5..g(1-N)) 

Try it online!Try it online!

JavaScript (ES7), 113 bytes

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N,c=X+x+~N,c-N,c,a+N].map((v,i)=>v*v+[b=y-Y,d=Y+y+~N,b-N,N-d,b+N,d][i]**2))**.5 

Try it online!

JavaScript (ES6), 104 bytes

Saved 9 bytes by refactoring in a way similar to what xnor did

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...(g=q=>[x,x+q,N-x].map((v,i)=>Math.hypot(X-v,Y-[y,N-y,y+q][i])))(N++),...g(1-N)) 

Try it online!

saved 2 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7), 115113 bytes

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N,c=X+x+~N,c-N,c,a+N].map((v,i)=>(v*v+[b=y=>v*v+[b=y-Y,d=Y+y+~N,b-N,N-d,b+N,d][i]**2))**.5)) 

Try it online!Try it online!

JavaScript (ES7), 115 bytes

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N,c=X+x+~N,c-N,c,a+N].map((v,i)=>(v*v+[b=y-Y,d=Y+y+~N,b-N,N-d,b+N,d][i]**2)**.5)) 

Try it online!

JavaScript (ES7), 113 bytes

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N,c=X+x+~N,c-N,c,a+N].map((v,i)=>v*v+[b=y-Y,d=Y+y+~N,b-N,N-d,b+N,d][i]**2))**.5 

Try it online!

Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (ES7), 115 bytes

Expects (N,x1,y1,x2,y2).

(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N,c=X+x+~N,c-N,c,a+N].map((v,i)=>(v*v+[b=y-Y,d=Y+y+~N,b-N,N-d,b+N,d][i]**2)**.5)) 

Try it online!