Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 649 characters in body
Source Link
nwellnhof
  • 10.6k
  • 1
  • 20
  • 38

Perl 6, 81 bytes

{min [X]([Z]($^p)>>.minmax).map:{$p.map({(@_ Z-$_)>>2.sum**.5}).max.ceiling,$_}}

Try it online!

Takes a list of points as 2-element lists ((X1, Y1), (X2, Y2), ...). Returns a list (R, (X, Y)). Uses the same approach as Pietu1998's Jelly answer:

[X]([Z]($^p)>>.minmax) # All possible centers within the bounding box
.map:{ ... } # mapped to
$p.map({(@_ Z-$_)>>2.sum**.5}).max # maximum distance from any point
.ceiling # rounded up,
,$_ # paired with center.
min # Find minimum by distance.

The minmax method is useful here as it returns a Range. The Cartesian product of ranges directly yields all points with integer coordinates.

Perl 6, 81 bytes

{min [X]([Z]($^p)>>.minmax).map:{$p.map({(@_ Z-$_)>>2.sum**.5}).max.ceiling,$_}}

Try it online!

Perl 6, 81 bytes

{min [X]([Z]($^p)>>.minmax).map:{$p.map({(@_ Z-$_)>>2.sum**.5}).max.ceiling,$_}}

Try it online!

Takes a list of points as 2-element lists ((X1, Y1), (X2, Y2), ...). Returns a list (R, (X, Y)). Uses the same approach as Pietu1998's Jelly answer:

[X]([Z]($^p)>>.minmax) # All possible centers within the bounding box
.map:{ ... } # mapped to
$p.map({(@_ Z-$_)>>2.sum**.5}).max # maximum distance from any point
.ceiling # rounded up,
,$_ # paired with center.
min # Find minimum by distance.

The minmax method is useful here as it returns a Range. The Cartesian product of ranges directly yields all points with integer coordinates.

Source Link
nwellnhof
  • 10.6k
  • 1
  • 20
  • 38

Perl 6, 81 bytes

{min [X]([Z]($^p)>>.minmax).map:{$p.map({(@_ Z-$_)>>2.sum**.5}).max.ceiling,$_}}

Try it online!

AltStyle によって変換されたページ (->オリジナル) /