Skip to main content
added 49 characters in body
Source Link

julia, 104104 97 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=u&v=((h=u-v.-.5)'h)^.5;minimum5 g(N,a,b)=minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),xvcat.((r=0:.005:N)',r)) 

Attempt This Online!Attempt This Online!

Thanks to MarcMush for a 7-byte improvement!

How?

(N, a, b) -> ( # Create a grid of pairs [x1, x2] spanning [0, N]^2. x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v.  u&v = ((h=uh = u - v .- .5)'h)^.5;5 # Minimise the function w -> d(a, w) + d(b, w') g(N, a, b) = minimum( # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise.  # Minimise the function w -> d(a, w) + d(b, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w),      # xMap over a grid of pairs [x1, x2] spanning [0, N]^2.   vcat.((r = 0:.005:N)', r) ) 

julia, 104 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=((h=u-v.-.5)'h)^.5;minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),x)) 

Attempt This Online!

How?

(N, a, b) -> ( # Create a grid of pairs [x1, x2] spanning [0, N]^2. x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v.  u&v = ((h=u-v.-.5)'h)^.5; # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise.  # Minimise the function w -> d(a, w) + d(b, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w), x ) ) 

julia, 104 97 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

u&v=((h=u-v.-.5)'h)^.5 g(N,a,b)=minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),vcat.((r=0:.005:N)',r)) 

Attempt This Online!

Thanks to MarcMush for a 7-byte improvement!

How?

# u&v is the distance between u-0.5 (centre of cell u) and v. u&v = ((h = u - v .- .5)'h)^.5 # Minimise the function w -> d(a, w) + d(b, w') g(N, a, b) = minimum( # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise. w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w),      # Map over a grid of pairs [x1, x2] spanning [0, N]^2.   vcat.((r = 0:.005:N)', r) ) 
added 3 characters in body
Source Link

julia, 104 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=((h=u-v.-.5)'h)^.5;minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),x)) 

Attempt This Online!

How?

(N, a, b) -> ( # createCreate a grid of pairs [x1, x2] spanning [0, N]^2. x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v. u&v = ((h=u-v.-.5)'h)^.5; # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise. # minimiseMinimise the function w -> d(a, w) + d(ab, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w), x ) ) 

julia, 104 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=((h=u-v.-.5)'h)^.5;minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),x)) 

Attempt This Online!

How?

(N, a, b) -> ( # create a grid of pairs [x1, x2] spanning [0, N]^2 x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v u&v = ((h=u-v.-.5)'h)^.5; # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise # minimise the function w -> d(a, w) + d(a, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w), x ) ) 

julia, 104 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=((h=u-v.-.5)'h)^.5;minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),x)) 

Attempt This Online!

How?

(N, a, b) -> ( # Create a grid of pairs [x1, x2] spanning [0, N]^2. x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v. u&v = ((h=u-v.-.5)'h)^.5; # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise. # Minimise the function w -> d(a, w) + d(b, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w), x ) ) 
Source Link

julia, 104 bytes

This solution uses the quotient space metric. For the projective plane, if \$\sim\$ is the equivalence relation induced by the edge identification (i.e. \$(p, 0) \sim (N-p, N); (0, p) \sim (N, N-p)\$) and \$d\$ is the Euclidean metric, then the projective plane metric is $$ d'(a, b) = \min_{w \sim w'} [d(a, w) + d(b, w')]. $$

To implement this, we create two grids \$x\$ and \$y\$ spanning \$[0, N]^2\$ such that \$x_{ij} \sim y_{ij}\$ and compute \$d(a, x_{ij}) + d(b, y_{ij})\$ for each corresponding pair of grid entries.

We make the vertical spacing between grid points \$0.005\$ to make sure that the result is correct to two decimal places.

(N,a,b)->(x=vcat.((r=0:.005:N;),r');u&v=((h=u-v.-.5)'h)^.5;minimum(w->a&w+b&((N.-2w)any(w.%N.==0)+w),x)) 

Attempt This Online!

How?

(N, a, b) -> ( # create a grid of pairs [x1, x2] spanning [0, N]^2 x = vcat.((r = 0:.005:N;), r'); # u&v is the distance between u-0.5 (centre of cell u) and v u&v = ((h=u-v.-.5)'h)^.5; # (N .- 2w)any(w .% N .== 0) + w is N-w on the edges of x and w otherwise # minimise the function w -> d(a, w) + d(a, w') over the grid x minimum( w -> a&w + b&((N .- 2w)any(w .% N .== 0) + w), x ) )