g | x | w | all
Bytes Lang Time Link
029JavaScript Node.js240707T103851Zl4m2
004Japt230510T083035ZShaggy
021Julia230909T054945ZCzylabso
019Factor + math.unicode230908T161734Zchunes
059C gcc230530T180645ZPeter
007BQN230605T175913Zchunes
028R230530T225335ZGiuseppe
004Thunno 2 M230512T172023ZThe Thon
035Lua230530T223748Zbluswimm
022Excel230512T154248ZEngineer
021Ruby230512T052854ZG B
025Scala230510T074541Z138 Aspe
030Perl 5 pa230510T180136ZXcali
004Jelly230510T174639ZJonathan
019Desmos230510T164257ZAiden Ch
019Bash + Linux utilities230510T153820ZDigital
005Pyth230510T141039ZCursorCo
008J230510T111453Zovs
004Nekomata230510T082341Zalephalp
00405AB1E230510T073347ZKevin Cr
013Charcoal230510T072113ZNeil
028Python230509T230140Zblaketyr
007Ly230510T015805Zcnamejj
020Arturo230510T011828Zchunes
026Retina230509T233151ZNeil
3375Vyxal g230509T224204Zlyxal

JavaScript (Node.js), 29 bytes

x=>x.sort((a,b)=>a-b)[0]*x[2]

Try it online!

.

Japt, 5 4 bytes

Íë ×

Try it here

Julia, 24 21 bytes

-3 bytes: by @MarcMush

!a=(b=sort(a))[1]b[3]

Attempt This Online!

Factor + math.unicode, 19 bytes

[ sort <evens> Π ]

Attempt This Online!

Sort the input, get the elements at even indices, then take the product.

C (gcc), 59 bytes

g(a,b)int*a,*b;{b=*a-*b;}f(int*l){qsort(l,4,4,g);*l*=l[2];}

Try it online!

Takes a 4-element integer array as input and stores the result in the first element of that array. It can probably be shortened, but it's still one of my better submissions :)

Explanation:

// This will be used as a comparison function for qsort(), so that
// integers can be sorted in ascending order.
g(a,b)int*a,*b;
{
    b=*a-*b;
}

f(int*l)
{
    // Sort l, assuming it has 4 elements with element size 4 (which is usually 
    // the size of integers in bytes), and using g() as a comparator.
    qsort(l,4,4,g);
    
    // Stores the first (minimum) element of l times the second-largest element 
    // in the first element of l.
    *l*=l[2];
}

46-byte version using some complicated flag (-zexecstack), suggested by @ceilingcat:

f(int*l){qsort(l,4,4,"\x8b\7+\6ð");*l*=l[2];}

Try it online!

BQN, 7 bytes

×´0‿2⊏∧

Try it

      ∧ # ascending sort
  0‿2⊏  # select first and third elements
×´      # product

R, 28 bytes

function(l)min(l)*sort(l)[3]

Try it online!

-2 bytes thanks to pajonk.

R, 30 bytes

function(l)prod(sort(l)[!0:1])

Try it online!

Thunno 2 M, 4 bytes

Ṡz€p

Attempt This Online!

Explanation

Ṡz€p  # Implicit input
Ṡ     # Sort in ascending order
 z    # Uninterleave ([a, b, c, d] -> [[a, c], [b, d]])
  €p  # Product of each inner pair
      # Implicit output of minimum (M flag)

Lua, 35 bytes

table.sort(arg)print(arg[1]*arg[3])

Try it online!

Excel, 22 bytes

=MIN(A:A)*SMALL(A:A,3)

The SMALL() function finds the nth smallest number in a range.

ScreenshotA

ScreenshotB

Ruby, 21 bytes

->*l{l.sort![2]*l[0]}

Try it online!

Nothing particularly original here.

Scala, 25 bytes

Saved bytes thanks to the comments of @corvus_192 and @user


Golfed version (25 bytes). Try it online!

a=>a.min*a.sorted.tail(1)

Alternative:

//scala 3
import scala.util.chaining._
def f(a:Int*):Int = a.sorted.pipe(a=>a(0)*a(2))

Perl 5 -pa, 30 bytes

$_=(@F=sort{$a-$b}@F)[0]*$F[2]

Try it online!

Jelly, 4 bytes

Ṣm2P

A monadic Link that accepts a list of the four fence lengths and yields the maximal yard area.

Try it online!

How?

Ṣm2P - Link: list of integers, F
Ṣ    - sort -> [a, b, c, d]
 m2  - modulo-2 slice -> [a, c]
   P - product -> a × c

Desmos, 19 bytes

f(l)=l.minl.sort[3]

Try It On Desmos!

Port of literally all the other answers here.

Bash + Linux utilities, 19

sort -n|dc -e??k?*p

Reads input from lines of STDIN.

Explanation

sort -n              # sort numerically
       |             # pipe to ...
        dc -e        # ... dc expression
             ??      # push [1] and [2]
               k     # pop [2] to precision register (unused)
                ?    # push [3]
                 *   # pop and multiply [1] and [3]
                  p  # print

Try it online!

Pyth, 5 bytes

*F%2S

Try it online!

Explanation

*F%2SQ    # implicitly add Q
          # implicitly assign Q = eval(input())
    SQ    # sort Q
  %2      # take every other element (so first and third)
*F        # reduce on multiplication

J, 8 bytes

]`*/@\:~

Attempt This Online!

Sort down, then reduce from the right by alternatingly taking the right value and multiplying:

    \:~2 8 5 9
9 8 5 2
    ]`*/9 8 5 2
9]8*5]2 -> 9]8*2 -> 9]16 -> 16

Nekomata, 4 bytes

o;*ṁ

Attempt This Online!

o;*ṁ
o       Sort
 ;      Nondeterministically split the list into two parts
  *     Multiply; fails if the two parts have different lengths
   ṁ    Take the minimum

05AB1E, 4 bytes

{ιPß

Try it online or verify all test cases.

Explanation:

{     # Sort the (implicit) input-quartet from lowest to highest
 ι    # Uninterleave it into two parts: [a,b,c,d]→[[a,c],[b,d]]
  P   # Get the product of both inner lists
   ß  # Get the minimum of this pair
      # (which is output implicitly as result)

Charcoal, 13 bytes

I×⌊θ⌈Φθ⁻κ⌕θ⌈θ

Try it online! Link is to verbose version of code. Takes input as a list of four elements. Explanation:

   θ            Input list
  ⌊             Take the minimum
 ×              Multiplied by
      θ         Input list
     Φ          Filtered where
        κ       Current index
       ⁻        Subtract i.e. is not equal to
            θ   Input list
           ⌈    Take the maximum
         ⌕      First index in
          θ     Input list
    ⌈           Take the maximum
I               Cast to string
                Implicitly print

Python, 28 bytes

lambda*a:min(a)*sorted(a)[2]

It's an anonymous function that when called returns the answer, like func(2,8,9,5) -> 16 or func(1,1,2,2) -> 2.

Unless I'm totally misunderstanding my own problem, I believe it can be solved by sorting the 4 input numbers and taking the smallest times the second biggest, since those sides will be matched parallel with the second smallest and the biggest respectively.

Like if the sorted inputs are a <= b <= c <= d then the biggest rect you can make will have area a * c, where side a is parallel to b and c parallel to d, and some of the b and d fences may have to be wasted.

(I'm a new user here so I'd love to know if this Python can be shortened at all. Thanks!)

Ly, 7 bytes

&napfp*

Try it online!

Similar to other solutions, this sorts the numbers the messes with the stack to get the smallest and second largest. Then it multiples them to get the answer.

&n       - read in all the numbers
  a      - sort
   p     - discard top (largest)
    f    - flip two entries (pushes 2nd largest down)
     p   - discard top (3rd largest)
      *  - multiple what's left (smallest and 2nd largest)
         - exits and prints what's on the stack as a number
      

Arturo, 20 bytes

$->a[sort'a a\0*a\2]

Try it

Sort the lengths then multiply the first by the third. Same algorithm as blaketyro arrived at independently.

Retina, 26 bytes

N`
.+¶.+¶(.+)¶.+
$.($&*$1*

Try it online! Takes input on separate lines but link is to test suite that splits on commas for convenience. Explanation: Port of @blaketyro's Python answer.

N`

Sort numerically.

.+¶.+¶(.+)¶.+
$.($&*$1*

Multiply the first number by the third.

Vyxal g, 27 bitsv1, 3.375 bytes

sI÷*

Try it Online!

What I was thinking is that the side lengths can be split into two groups: those likely to be the long side of the rectangle and those likely to be the short side.

The long side of the rectangle will be the second most longest side, as it's guaranteed to be smaller or equal to than the other longer side.

The short side of the rectangle will be the shortest side, as it's guaranteed to be smaller than or equal to the other short side.

For example:

[2, 5, 8, 9]

The side length of 9 can't be the long side because there's no matching 9. But the side length of 8 can be because it's got that length in the 9. Hence, the second smallest length is the long side.

The side length of 5 can't be the short side, because there's no matching 5. But the side length of 2 can be because it's got that length in 5. Hence the smallest length is the short side.

Explained

sI÷*
s    # sort the list ascending. The idea here is that the sides that are more likely to be the longer sides go to the end of the list and the ones likely to be the shorter sides go to the front. 
 I    # split the list into two halves - [shorts, longs] 
  ÷*  # dump each item onto the stack and multiply each item in shorts by each item in long. 
# the g flag gets the smallest item of that list, which is also the first item.