| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | JavaScript Node.js | 240707T103851Z | l4m2 |
| 004 | Japt | 230510T083035Z | Shaggy |
| 021 | Julia | 230909T054945Z | Czylabso |
| 019 | Factor + math.unicode | 230908T161734Z | chunes |
| 059 | C gcc | 230530T180645Z | Peter |
| 007 | BQN | 230605T175913Z | chunes |
| 028 | R | 230530T225335Z | Giuseppe |
| 004 | Thunno 2 M | 230512T172023Z | The Thon |
| 035 | Lua | 230530T223748Z | bluswimm |
| 022 | Excel | 230512T154248Z | Engineer |
| 021 | Ruby | 230512T052854Z | G B |
| 025 | Scala | 230510T074541Z | 138 Aspe |
| 030 | Perl 5 pa | 230510T180136Z | Xcali |
| 004 | Jelly | 230510T174639Z | Jonathan |
| 019 | Desmos | 230510T164257Z | Aiden Ch |
| 019 | Bash + Linux utilities | 230510T153820Z | Digital |
| 005 | Pyth | 230510T141039Z | CursorCo |
| 008 | J | 230510T111453Z | ovs |
| 004 | Nekomata | 230510T082341Z | alephalp |
| 004 | 05AB1E | 230510T073347Z | Kevin Cr |
| 013 | Charcoal | 230510T072113Z | Neil |
| 028 | Python | 230509T230140Z | blaketyr |
| 007 | Ly | 230510T015805Z | cnamejj |
| 020 | Arturo | 230510T011828Z | chunes |
| 026 | Retina | 230509T233151Z | Neil |
| 3375 | Vyxal g | 230509T224204Z | lyxal |
Factor + math.unicode, 19 bytes
[ sort <evens> Π ]
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];}
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];}
R, 28 bytes
function(l)min(l)*sort(l)[3]
-2 bytes thanks to pajonk.
R, 30 bytes
function(l)prod(sort(l)[!0:1])
Thunno 2 M, 4 bytes
Ṡz€p
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)
Excel, 22 bytes
=MIN(A:A)*SMALL(A:A,3)
The SMALL() function finds the nth smallest number in a range.
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))
Jelly, 4 bytes
Ṣm2P
A monadic Link that accepts a list of the four fence lengths and yields the maximal yard area.
How?
Ṣm2P - Link: list of integers, F
Ṣ - sort -> [a, b, c, d]
m2 - modulo-2 slice -> [a, c]
P - product -> a × c
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
Pyth, 5 bytes
*F%2S
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
]`*/@\:~
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;*ṁ
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*
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]
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÷*
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.

