g | x | w | all
Bytes Lang Time Link
075Janet250318T133609Zxigoi
049Julia 1.0230308T174949ZMarcMush
138Fortran GFortran230306T230832Zroblogic
009Vyxal ḋ230306T194028Zlesobrod
147C gcc201122T032746ZErikF
079Python 3201127T204652Zgarrison
067Factor201125T080343ZBubbler
082Python 3201123T101925ZJitse
077Perl 5 MListUtil=min201122T023728ZXcali
022Charcoal201121T232436ZNeil
074Haskell201121T190956ZAZTECCO
014Brachylog201121T200634ZUnrelate
029J201121T194539Zxash
093Python 3201121T030506ZNoodle9
065Ruby 2.7201121T061511Zvrintle
010Husk201121T155030ZDominic
072Scala 3201121T151455Zuser
086JavaScript ES6201121T091821ZArnauld
014Japt g201121T125800ZShaggy
034R201121T121339ZDominic
017Octave/MATLAB with Statistics package/toolbox201121T115144ZLuis Men
00805AB1E201121T083930Zovs
033Wolfram Language Mathematica201121T044156Zatt
009Jelly201121T030733Zfireflam

Janet, 89 75 bytes

|(min;(seq[a :in $ b :in $ :unless(= a b)](reduce2 math/hypot(map - a b))))

The points must be taken as arrays (not tuples) so that they are compared by reference.

Julia 1.0, 53 52 49 bytes

a>b...=min(>(b...),([a].>b)...)
a>b=hypot(a-b...)

Try it online!

This will work for bigger dimensions as well

Fortran (GFortran), 206... 138 bytes

function d(A,n);real A(3,n);t=huge(i)
do 5 k=1,n-1;do 5 j=2,n;s=0;do i=1,3;s=s+(A(i,k)-A(i,j))**2;enddo
5 if(s>0.and.t>s)t=s;d=sqrt(t);end

Try it online!  144  148  182  206

*line 1: sets up array, reads in data
*line 2: iterates over rows j,k, and sums the difference-squares
*line 3: compares current Euclidean squared distance s with tracking number t, taking the lower number, and ignores a distance of 0 (dupe points)

Saved 24 bytes by removing the allocate stuff and giving the array preset dimensions. A possible improvement for my other Fortran answers!
Saved another 34 bytes by using a subroutine and moving I/O to the main program. Replaced repeated enddos with a line number. Removed a placeholder variable q. Some inspiration taken from this fortran golf. I went looking for a useful intrinsic like NORM2 or HYPOT but couldn't find one for this problem.
Saved 4 bytes by replacing the subroutine with a function

Vyxal , 9 bytes

∪2ḋƛ÷∆d;g
∪           # Delete duplicates
 2ḋ         # All subsets of length 2
   ƛ÷∆d;    # Euclidean distance of every subset
        g   # Minimum

Try it Online!

C (gcc), 155 147 bytes

Thanks to ceilingcat for -8 and an interesting (ab)use of hypot!

Takes a counted array of coordinates.

#define g(x)hypot(c[x+j]-c[x+i],
i,j;float f(s,c,d,l)float*c,d,l;{for(l=-1,s*=3,i=0;i<s;i+=3)for(j=i;(j+=3)<s;l=l<0|d<l?d:l)d=g(2)g(1)g()0)));s=l;}

Try it online!

Python 3, 79 bytes

I'm new here and not completely sure this follows the rules, LMK if this isn't valid!

lambda p:min(sum((a-b)**2for a,b in zip(x,y))**.5for x in p for y in p if x!=y)

Factor, 67 bytes

[ dup [ v- norm ] cartesian-map [ head ] map-index concat infimum ]

Try it online!

Evaluates self-cartesian-product by vector distance, takes the lower triangular matrix (without diagonals), and evaluates the minimum of all values.

[                                ! anonymous lambda
  dup [ v- norm ] cartesian-map  ! self-cartesian-product by vector distance
  [ head ] map-index             ! for each array at index i, take first i elems
  concat infimum                 ! minimum of all values
]

Factor, 73 bytes

USE: math.combinatorics
[ 2 [ first2 v- norm ] map-combinations infimum ]

Try it online!

Factor has a built-in for generating combinations, but it is way too long (USE: math.combinatorics map-combinations is already 40 bytes).

Python 3, 82 bytes

f=lambda a,*b:[*b]and[min([sum((x-y)**2for x,y in zip(a,q))**.5for q in b]+f(*b))]

Try it online!


Python 3 with SciPy, 58 bytes

lambda*a:min(pdist(a))
from scipy.spatial.distance import*

Try it online!

Perl 5 -MList::Util=min,sum, 81 77 bytes

@KjetilS shaved 4 bytes.

sub f{min map{@b=@$_;map{sqrt sum map($_-$b[$j++%3])**2,@$_}@_[++$i..$#_]}@_}

Try it online!

Charcoal, 22 bytes

I₂⌊ΦEθ⌊E…θκΣXEλ⁻ν§ιξ²κ

Try it online! Link is to verbose version of code. Takes n-dimensional vectors. Explanation:

     θ                  Input list
    E                   Map over vectors
         θ              Input list
        …               Truncate to length
          κ             Outer index
       E                Map over remaining vectors
              λ         Inner vector
             E          Map over coordinates
                 §ιξ    Coordinate of outer vector
                ν       Current coordinate
               ⁻        Difference
            X       ²   Squared
           Σ            Summed
      ⌊                 Take the minimum square sum
   Φ                 κ  Filter out minimum of empty list
  ⌊                     Take the minimum
 ₂                      Take the square root
I                       Cast to string
                        Implicitly print

Haskell, 75 74 bytes

g[]=[]
g(x:t)=[(sum$zipWith((**2).)(map(-)x)z)**0.5|z<-t]++g t
f=minimum.g

Try it online!

g[]=[]        - edge case for combinations   
g(x:t)=[ ... |z<-t]++g t  
              - combinations
(sum$zipWith(\a b->(a-b)**2)x z)**0.5
              - compute hypo..
f=minimum.g   - return minimum value found

Brachylog, 14 bytes

{⊇Ċz-ᵐ^₂ᵐ+√}ᶠ⌋

Try it online!

Boring and straightforward.

             ⌋    The output is the minimum of
{          }ᶠ     every possible
          √       square root of
         +        a sum of
      ^₂ᵐ         the squares of
    -ᵐ            the differences between
   z              the coordinates for each axis
 ⊇                for a sublist of the input
  Ċ               containing two elements.

J, 29 bytes

[:<./@,+/&.:*:@:-"1/~+_*[:=#\

Try it online!

[:<./@,+/&.:*:@:-"1/~+_*[:=#\
                           #\ 1…N
                        [:=   identity matrix NxN
                      _*      times infinity
                     +        plus
                 "1/~         the table with the coordinate triples:
              @:-             a - b and
         &.:*:                under square
       +/                     summed
         &.:*:                reverse square
[:<./@,                       flatten the table and get the min entry

Python 3, 106 95 93 bytes

Saved 11 bytes thanks to fireflame241!!!
Saved 2 bytes thanks to Jonathan Allan!!!

lambda l:min(sum((a-b)**2for a,b in zip(l[p],v))**.5for q,v in enumerate(l)for p in range(q))

Try it online!

Inputs a list of points as tuples and returns the Euclidean distance between the two closest points.
Works with points of any dimension so long as they are consistent within the list.

Ruby 2.7, 79 65 bytes

Saved a whooping 14 bytes, thanks to Sisyphus!

->s{s.combination(2).map{_1.zip(_2).sum{|a,b|(a-b)**2}**0.5}.min}

Try it online!

Husk, 10 bytes

▼ṁẊȯ√ṁ□z-Ṗ

Try it online!

▼           # minimum of
 ṁ          # sums of applying function to
         Ṗ  # all subsets of input
            # (this may include subsets of >2 points,
            # but that's ok...)
  Ẋȯ√ṁ□z-   # the function:
  Ẋȯ        # apply to all adjacent pairs
            # (...that's why it was ok if there were >2 points
            # in any sublist)
    √       # square root of
     ṁ□     # sum of squres of
       z-   # element-wise differences

Scala 3, 72 bytes

s=>math.sqrt((for> <-s;| <-s- >yield(>zip|map(_-_)map(x=>x*x)).sum).min)

Try it online!

Accepts a Set[List[Int]] so that it can use - to ensure a point is not compared to itself.

This is my first time using Scala 3's new control syntax to save 2 bytes.

JavaScript (ES6), 86 bytes

a=>a.map(m=([x,y,z],i)=>a.map(([X,Y,Z])=>m=!i--|(d=Math.hypot(x-X,y-Y,z-Z))>m?m:d))&&m

Try it online!

Commented

a =>                          // a[] = list of triplets
  a.map(m = ([x, y, z], i) => // for each triplet (x,y,z) at position i in a[]:
    a.map(([X, Y, Z]) =>      //   for each triplet (X,Y,Z) in a[]:
      m =                     //     update the minimum distance m:
        !i-- | (              //       decrement i; if it was equal to 0
          d = Math.hypot(     //       or the Euclidean distance d:
            x - X,            //         between (x,y,z)
            y - Y,            //         and (X,Y,Z)
            z - Z             //
        )) > m ?              //       is greater than m:
          m                   //         leave m unchanged
        :                     //       else:
          d                   //         update m to d
    )                         //   end of inner map()
  ) && m                      // end of outer map(); return m

Japt -g, 15 14 bytes

The spec asks us to get the minimum but the lone test case gets the maximum so I don't know which to output. I've gone with the former but if that's not right then use the -h flag instead.

à2 ËÕËrnÃx²¬ÃÍ

Try it

R, 34 bytes

function(...)min(dist(rbind(...)))

Try it online!

This is a nice opportunity to use R's ... syntax to define a function that can accept a variable number of arguments; in this case, the x,y,z coordinates of each point.

The dist function calculates the pairwise distance between all rows of a matrix, using a chosen method - luckily, the default is 'euclidean' and so isn't specified in this case.

Of course, it could be even shorter if we allow the input to already be combined-together as a matrix, but this wouldn't be so neat...

R, 23 bytes

function(m)min(dist(m))

Try it online!

Octave/MATLAB with Statistics package/toolbox, 17 bytes

@(x)min(pdist(x))

Try it online!

05AB1E, 8 bytes

œ€ü-nOtß

Try it online!

Commented:

œ         # take all permutations of the input
 €        # for each permutation:
   -      #   take the element-wise difference
  ü       #   between each pair of adjacent points
    n     # square each number
     O    # sum all difference-lists
      t   # take the square root of every sum
       ß  # take the minimum

Wolfram Language (Mathematica), 33 bytes

Min[Norm[#-#2]&@@@#~Subsets~{2}]&

Try it online!

Jelly, 9 bytes

ŒcZ_/²§Ṃ½

Try it online!

Works with points of any dimension

Explanation

ŒcZ_/²§Ṃ½ # Take as input a list of points, where each point is a list of coordinates
Œc        # All pairs of two distinct points [(p1,p2),(p1,p3),...]
  Z       # Transpose to get two lists of points [[p1,p1,...],[p2,p3,...]]
   _/     # Depth-1 vectorizing difference [p1-p2, p1-p3, ...]
     ²§   # Square coordinates and sum each
       Ṃ  # Minimum
        ½ # Square root