23
2
This challenge is about finding the smallest disk that contains some given points. This is made somewhat trickier, however, by the fact that in this challenge, the disk's coordinates and radius must both be integers.
Your input will be a list of points with integer coordinates x
and y
. You can take this as a list of tuples, a list of lists, or any other way to represent a collection of pairs. x
and y
will both be (possibly negative) integers. Every point is guaranteed to be unique, and there will be at least one point.
Your output will be a disk in the form of three numbers, X
, Y
, and R
. X
, Y
, and R
are all integers, X
and Y
represent the disk's center and R
represents its radius. The distance between every given point and the center must be less than or equal to R
, and there must not exist such a disk with a smaller R
that also satisfies this condition.
It is possible that there will be multiple possible solutions for a given input, your code must output at least one of them in this case.
You can use any kinds of geometry builtins your language supports if there are any, and input/output may be through built-in point/disk objects instead of just numbers.
Test Cases
Input (Possible) Output(s)
(x,y) (X,Y,R)
-------------------------
(0,0) (0,0,0)
-------------------------
(0,1) (0,0,1)
(1,0) (1,1,1)
-------------------------
(1,4) (4,4,3)
(3,2)
(4,1)
(4,5)
(5,2)
(7,4)
-------------------------
(-1,0) (0,0,2)
(2,0) (1,0,2)
-------------------------
(-1,0) (1,0,2)
(2,1) (0,1,2)
-------------------------
(0,0) (1,0,1)
(1,1) (0,1,1)
Fewest bytes wins.
Sandbox – Pavel – 2018-11-06T16:39:50.553
Found a couple typos, if you don't mind me pointing them out: "This is made somewhat trickier..."; "...represents the disk's center and R represents its radius..."; "...and there must not exist such a disk..." – J. Sallé – 2018-11-06T17:06:02.127
2Usually making things integer just make code-golf easier. – user202729 – 2018-11-06T17:13:55.280
@KevinCruijssen That's by coincidence. Inputs can be in any order. – Pavel – 2018-11-06T18:04:53.690
1@Pavel The input can be in any order, or we can take the input in any order? As in, the input can be in any order and we should manually sort first in our solution, or can we already take the input pre-sorted? – Kevin Cruijssen – 2018-11-06T18:07:54.927
@KevinCruijssen Any order implies not sorted. You should not make any assumptions about the input already following a certain rule. – Pavel – 2018-11-06T18:10:05.310