g | x | w | all
Bytes Lang Time Link
041JavaScript Node.js240202T110903Zl4m2
007Uiua SBCS240202T104754Zchunes
118Pascal230721T145513ZKai Burg
004Thunno 2230721T064759ZThe Thon
010Vyxal210711T111520ZWasif
100C clang210606T124525ZStack Ex
4812MMIX210606T020805ZNoLonger
039Scala210605T202959Zcubic le
020Factor + sets.extras math.unicode210605T195854Zchunes
011Stax210131T152251ZRazetime
006Brachylog210131T142257ZUnrelate
045TI BASIC200212T154134ZTiKevin8
013Stax200220T181953ZNanajnai
7271PHP200210T184550ZGuillerm
9279PHP200213T154142Z640KB
155SQL200213T023742ZForty3
027Perl 6200213T010708Znwellnho
043Kotlin200212T171758ZQuinn
060C#200211T192116Zuser9206
036R200212T075917ZCriminal
042Excel Version 1911200210T201925Zemegolf1
037R200210T231946ZRobin Ry
178Whitespace200211T150305ZKevin Cr
060Excel200211T142303ZWernisch
074Racket200211T122637ZGalen Iv
037Haskell200211T084018Zxnor
038Ruby200211T073722ZG B
048Python200211T052330Zxnor
010APL Dyalog200211T034329ZJo King
031Wolfram Language Mathematica200211T020246ZZaMoC
039Zsh200211T004303ZGammaFun
006Japt200210T182054ZShaggy
061Python 3200210T180701ZRGS
026Bash + GNU utilities200210T203203ZDigital
052Python 2200210T223651Zovs
051Retina200210T214751ZNeil
011Charcoal200210T212929ZNeil
006Jelly200210T194655ZJonathan
044PowerShell200210T194532Zmazzy
040Mathematica200210T200839ZRGS
042C gcc200210T185241ZNoodle9
010J200210T194028ZFrownyFr
038JavaScript ES6200210T183049ZArnauld
031GolfScript200210T190953ZMathgeek
044Perl 5 MListUtil=product apl200210T180812ZXcali
097PowerShell200210T184924ZAdmBorkB
024Burlesque200210T175313ZDeathInc
00305AB1E200210T180547ZGrimmy

JavaScript (Node.js), 41 bytes

f=(a,b,c)=>a>f||f(b,c,[a])*(a-b&&a-c?a:1)

Try it online!

For shorter solution Arnauld has a 38 one

Uiua SBCS, 7 bytes

/×⊚=1°⊚

Try it!

Pascal, 118 Bytes

This function uses the set-member-iteration statement (for … in … do) and the symmetric difference operator ><. Therefore it needs a processor at least supporting features of ISO standard 10206 “Extended Pascal” (level 0).

function f(a,b,c:integer):integer;var r:integer;begin r:=1;if[a,b,c]<>[a]then for a in[a]><[b]><[c]do r:=r*a;f:=r end;

Ungolfed:

function f(a, b, c: integer): integer;
var
    result: integer;
begin
    { `result` needs to be initialized for the `for`-loop below. }
    result := 1;
    
    { If not sidelengths of an equilateral triangle: }
    if [a, b, c] <> [a] then
    begin
        { Symmetric difference of sets. }
        for a in [a] >< [b] >< [c] do
        begin
            result := result * a;
        end;
        { NB: The iterator variable `a` retains its original value
          unless you escape the `for`-statement with a `goto`. }
    end;
    
    { In Pascal there must be _exactly_ one assignment
      to the implicitly declared variable bearing the function’s name.
      Hence we cannot simply re-use `f` as the `result` variable. }
    f := result;
end;

Thunno 2, 4 bytes

cḅịp

Try it online!

Explanation

cḅịp  # Implicit input
c     # Counts of each number
  ị   # Only keep items of the input
 ḅ    # where the count equals 1
   p  # Product of this list

Vyxal, 10 bytes

Ċ't1=;f1JΠ

Try it Online!

C (clang), 199 100 bytes

a,b;main(c){scanf("%i%i%i",&a,&b,&c);printf("%i",a-b|b-c?a-b|b==c?b-c|c==a?a-c|c==b?a*b*c:b:a:c:1);}

Try it online!

Don't know C? Here's how it works. We initialize 3 integers, give them input, then proceeds to multiple if-statements to check whether or not they're equal.

Thanks to ceilingcat for golfing a whopping 99 bytes.

MMIX, 48 bytes (12 instrs)

foo CMP $255,$0,$1
    CMP $3,$1,$2
    BZ  $255,0F     // if(a == b) goto ab
    BZ  $3,1F       // if(b == c) goto bc
    CMP $255,$0,$2
    BZ  $255,2F     // if(a == c) goto ac
    MUL $0,$0,$1    // a *= b
    MUL $0,$0,$2    // a *= c
1H  POP 1,0         // bc: return a
0H  CSZ $2,$3,1     // ab: if(b == c) c = 1
    POP 3,0         // return c
2H  POP 2,0         // ac: return b

Scala, 39 bytes

f=>f.filter(i=>f.count(_==i)<2).product

Try it online!

Factor + sets.extras math.unicode, 20 bytes

[ non-repeating Π ]

Try it online!

Factor has a word non-repeating that gives you every element of a sequence that doesn't repeat. Turns out the answer to this question is just taking the product of this.

Stax, 11 bytes

äùóq◘0Jg•UÜ

Run and debug it

This one works for all testcases, and shorter! Uses Unrelated String's idea.

Explanation

o{}/{Dz_?m$:*
o             order the array
 {}/          group equal adjacent values
    {    m    map to the following:
        ?     if:
     D        deleting the first element
              makes the array empty, then:
       _       push it again
      z        otherwise push an empty list
          $   flatten the result
           :* take the product 

Brachylog, 6 bytes

≡ᵍ~gˢ×

Try it online!

 ᵍ        Group elements by
≡         value.
    ˢ     For each group,
  ~g      if it is a singleton list, extract its only element,
    ˢ     else discard it.
     ×    Take the product.

TI BASIC, 45 Bytes

Prompt A,B,C
ABC
If A=B
C
If A=C
B
If B=C
A
If A=B and A=C
1
Ans

Stax, 13 bytes

üΩ1↑♂Åò←3♠'W▐

Run and debug it

PHP, 72 71 bytes

sort($argv);[,$a,$b,$c]=$argv;echo$a-$b?$b-$c?$a*$b*$c:$a:($b-$c?$c:1);

Try it online!

Might be shorter without the sort but nested ternary operator precedence blows my mind.

-1 byte thanks to @640KB

PHP, 66 bytes

fn($a,$b,$c)=>$a-$c?$a-$b?$b-$c?$a*$b*$c:$a:$b==$c?:$c:$b==$c?:$b;

Try it online!

Kudos to @640KB for taming the ternary operator beast!

PHP, 92 79 bytes

fn($a)=>array_product(array_keys(array_intersect(array_count_values($a),[1])));

Try it online!

This isn't going to win for brevity, but just thought I'd try it entirely using chained PHP array functions.

Now using @Guillermo Phillips's suggestion for PHP 7.4 arrow function syntax to save 13 bytes.

PHP, 66 bytes

fn($a,$b,$c)=>$a-$c?$a-$b?$b-$c?$a*$b*$c:$a:$b==$c?:$c:$b==$c?:$b;

Try it online!

And another crazy ternary version inspired by @Guillermo Phillips's answer!

SQL, 245 155 bytes

 DECLARE @a INT=2,@b INT=4,@c INT=8;WITH v AS(SELECT x FROM(VALUES(@a),(@b),(@c))t(x) GROUP BY x HAVING COUNT(*)=1)SELECT ISNULL(EXP(SUM(LOG(x))), 1) FROM v

Expanded:

DECLARE @a INT=2,
        @b INT=4,
        @c INT=8;

WITH v
     AS (SELECT x
           FROM(VALUES(@a),
                      (@b),
                      (@c))t(x)
          GROUP BY x
         HAVING COUNT(*) = 1)
SELECT ISNULL(EXP(SUM(LOG(x))), 1)
  FROM v

The straightforward solution is only 150 .. but it is boring. :)

DECLARE @a INT=2,@b INT=4,@c INT=2;SELECT CASE WHEN @a=@b AND @a=@c THEN 1 WHEN @a=@b THEN @c WHEN @b=@c THEN @a WHEN @a=@c THEN @b ELSE @a*@b*@c END
DECLARE @a INT=2,
        @b INT=4,
        @c INT=2;

SELECT CASE
         WHEN @a = @b
              AND @a = @c THEN 1
         WHEN @a = @b THEN @c
         WHEN @b = @c THEN @a
         WHEN @a = @c THEN @b
         ELSE @a * @b * @c
       END 

Perl 6, 27 bytes

{[*] .Bag.grep(0=>1)>>.key}

Try it online!

(Using a Pair as matcher compares only values and ignores the key.)

Kotlin, 52 51 43 bytes

filter{z->count{z==it}<2}.fold(1){s,c->s*c}

Try it online!

C#, 60 bytes

int f(int a,int b,int c)=>a==b?a==c?1:c:a==c?b:b==c?a:a*b*c;

R, 36 bytes

prod((a=rle(sort(scan())))$v[a$l<2])

Try it online!

rle() shows its worth again. Feels like some parentheses could be golfed out somehow.

The fact that prod() of an empty numeric evaluates to 1 is the only reason this is efficient.

Excel (Version 1911), 80 Bytes, 42 Bytes

=PRODUCT(FILTER(A1#,COUNTIF(A1#,A1#)=1,1))

Input entered as a static column array (e.g. ={1;2;3}) in cell A1

R, 40 37 bytes

-3 bytes by taking input with scan().

prod(unique(x<-scan())^2,1/x)^!!sd(x)

Try it online!

sd(x) computes the standard deviation (which is 0 iff all entries are equal), so !!sd(x) is TRUE if some entries are different, and FALSE if all are equal.

This is shorter than anything I could come up with based on table, tabulate, duplicated or rle(sort()).

Whitespace, 178 bytes

[S S S N
_Push_0][S N
S _Dupe_0][T    N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input_A][S N
S _Dupe_input_A][S N
S _Dupe_input_A][T  N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input_B][S N
S _Dupe_input_B][S N
S _Dupe_input_B][T  N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input_C][S N
S _Dupe_input_C][S T    S S T   S N
_Copy_0-based_2nd_input_B][T    S S T   _Subtract][N
T   S S N
_If_0_Jump_to_Label_C==B][S N
S _Dupe_input_C][S T    S S T   T   N
_Copy_0-based_3rd_input_A][T    S S T   _Subtract][N
T   S T N
_If_0_Jump_to_Label_C!=B&&C==A][S T S S T   S N
_Push_0-based_2nd_input_A][S T  S S T   S N
_Push_0-based_2nd_input_B][T    S S T   _Subtract][N
T   S N
_If_0_Jump_to_Label_PRINT][T    S S N
_Multiply][T    S S N
_Multiply][N
S N
N
_Jump_to_Label_PRINT][N
S S T   N
_Create_Label_C!=B&&C==A][S N
N
_Discard_input_C][N
S N
N
_Jump_to_Label_PRINT][N
S S S N
_Create_Label_C==B][S N
S _Dupe_input_C][S T    S S T   T   N
_Copy_0-based_3rd_input_A][T    S S T   _Subtract][N
T   S T T   N
_If_0_Jump_to_Label_C==B&&C==A][S N
N
_Discard_input_C][S N
N
_Discard_input_B][N
S N
N
_Jump_to_Label_PRINT][N
S S T   T   N
_Create_Label_C==B&&C==A][S S S T   N
_Push_1][N
S S N
_Create_Label_PRINT][T  N
S T _Print_as_integer]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Whitespace work-flow:

Integer A = STDIN as integer
Integer B = STDIN as integer
Integer C = STDIN as integer                   (the stack now contains [A,B,C])
If(C==B): Jump to Label C==B
If(C==A): Jump to Label C!=B&&C==A
If(A==B): Jump to Label PRINT                  (top of the stack is here C)
Multiply top two
Multiply top two
Jump to Label PRINT                            (top of the stack is here A*B*C)

Label C!=B&&C==A:
  Discard top (C)
  Jump to Label PRINT                          (top of the stack is here B)
Label C==B:
  If(C==A): Jump to Label C==B&&C==A
  Discard top (C)
  Discard top (B)
  Jump to Label PRINT                          (top of the stack is here A)

Label C==B&C==A
  Push 1                                       (top of the stack is here 1)
Label PRINT
  Print top of the stack as integer to STDOUT

Since the inputs are guaranteed to be positive, it uses heap-address 0 for input A; heap-address A for input B; and heap-address B for input C.

Excel, 60 bytes

=IF(A1=B1,IF(A1=C1,1,C1),IF(B1=C1,A1,IF(A1=C1,B1,A1*B1*C1)))

Does not use features like FILTER, only available to Office Insiders.

Racket, 74 bytes

λ(n)(apply *(map(λ(x)(if(=(length x)1)(car x)1))(group-by identity n))))

Try it online!

Haskell, 37 bytes

f l=product[x|x<-l,filter(==x)l==[x]]

Try it online!

Pretty straightforward -- filter for elements that appear only once and take the product.

Ruby, 38 bytes

->*a{r=1;a.map{|w|(a-[w])[1]&&r*=w};r}

Try it online!

Python, 48 bytes

lambda l:eval("(%sin[%s,%s]or %s)*"*3%(l*4)+"1")

Try it online!

Takes in a tuple. The idea is similar to an answer in the Code Review question, which can be golfed to:

51 bytes

lambda a,b,c:a**(b!=a!=c)*b**(c!=b!=a)*c**(a!=c!=b)

Try it online!

Each element is included in the product if it's different from the other two, with the power setting to a harmless x**0 == 1 otherwise. We want to avoid writing the three similar terms being multiplied. Python unfortunately doesn't have a built-in list product without imports. So, we turn to eval shenanigans.

We use a longer expression that use logical short-circuiting:

60 bytes

lambda a,b,c:(a in[b,c]or a)*(b in[c,a]or b)*(c in[a,b]or c)

Try it online!

In this expression, the variable names cycle through a,b,c in that order four times. So, by tripling the format string "(%sin[%s,%s]or %s)*" and plugging in the input tuple repeated four times, we get the desired expression. We just need to append a "1" to deal with the trailing multiplication.

APL (Dyalog), 10 bytes

Thanks to Adám and Bubbler in chat for helping golf this

×/∪*1=⊢∘≢⌸

Try it online!

Explanation:

×/             ⍝ Reduce by multiplication
  ∪            ⍝ The unique values of the input
   *           ⍝ To the power of
    1=         ⍝ Whether one is equal to
        ≢      ⍝ The length of
      ⊢∘ ⌸     ⍝ The indexes of each unique element

Wolfram Language (Mathematica), 31 bytes

#&@@Times@@Tally@#~Cases~{_,1}&

Try it online!

Zsh, 39 bytes

(){i=1
for n;((i*=${(M)#@:#$n}>1?1:n))}

Try it online!

For the first time, I can say that a zsh math function actually won out over a normal program! I knew there was potential when I got a tie a while back, here's the relevant meta post if you want to know more about them.

The meat of this is the loop where we test for distinctness:

${(M)#@:#$n}
${   #     }    # count
${(M)      }    # matches
${    @:#  }    # on the positional parameters.
${       $n}    # against $n
            >1  # more than 1 (not distinct)

We use a ternary to decide to multiply by 1 or n.

Japt, 9 6 bytes

ü l1 ×

Try it

Python 3, 63 62 61bytes

lambda l:prod(x for x in l if l.count(x)<2)
from math import*

You can try it online!

Thanks @FryAmTheEggman for saving me 1 byte.

Bash + GNU utilities, 26

sort|uniq -u|dc -e1?*?*?*p

The 3 input integers are each given on their own line.

In the case of non-distinct inputs, dc warnings are printed to stderr. These may be ignored.

uniq -u does most of the heavy lifting here. With the -u option, only non-duplicated lines are returned. uniq requires its input to be sorted.

The dc expression pushes 1 to the stack, then reads up to 3 integers, multiplying each in turn, then printing the output. If uniq pipes less than 3 integers to dc, then the surplus ? will not add to the stack and the following * will spit out a warning because * needs to pop 2 operands from the stack. But these are just warnings, dc continues execution until it prints the final product.

Try it online!

Python 2, 52 bytes

l=input();r=1
for x in l:r*=1%l.count(x)or x
print r

Try it online!

Retina, 51 bytes

N`\d+
\b(\d+)(,\1)+\b

~["^.*¶$.("|""]'_L$`\d+
$&$*

Try it online! Link includes test cases. Explanation:

N`\d+

Sort the input list.

\b(\d+)(,\1)+\b

Delete all duplicated numbers.

L`\d+

List all the remaining numbers, discarding any commas.

$`
$&$*

Suffix each number with a *.

|""`

Don't separate the numbers.

["^.*¶$.("`

Prefix the result with ^.* on its own line and $.( on the same line as the numbers.

]'_`

Suffix the result with a _.

~`

Evaluate the result on the previous contents of the buffer. This results in one of three evaluations:

  1. If all three numbers were identical, it evaluates this:

    ^.*
    $.(_
    
  2. If two numbers were identical, it evaluates this:

    ^.*
    $.(5*_
    
  3. If the numbers were distinct, it evaluates this:

    ^.*
    $.(1*2*3*_
    

This takes the string _, and repeats it by the remaining numbers in turn, and then takes the length of the result, which is exactly the same as the product of the numbers, or 1 if there were none left.

Charcoal, 11 bytes

IΠEθ⎇⊖№θι¹ι

Try it online! Link is to verbose version of code. Explanation:

   θ        Input array
  E         Map over elements
      №     Count of
        ι   Current element
       θ    In input array
     ⊖      Decremented
    ⎇       Ternary
          ι If count was 1 then original element
         ¹  Otherwise literal 1
 Π          Take the product
I           Cast to string for implicit print

I found other ways of formulating the condition, but they were all the same length. Alternate approach, also 11 bytes:

IΠ∨Φθ⁼¹№θι¹

Try it online! Link is to verbose version of code. Explanation:

    θ       Input array
   Φ        Filter where
       №    Count of
         ι  Current element
        θ   In input array
     ⁼      Equals
      ¹     Literal 1
  ∨         Or if list is now empty
          ¹ Then literal 1
 Π          Take the product
I           Cast to string for implicit print

Jelly,  7  6 bytes

ḟœ-Q$P

Try it online!

How?

ḟœ-Q$P - list, L
    $  - last two links as a monad:
   Q   -   de-duplicate (L)
 œ-    -   (L) multi-set difference (that)
ḟ      - (L) filter discard if in (that)
     P - product

7s:

ĠṖÐḟị⁸P
ḟṖƙ`F$P

PowerShell, 44 bytes

,1+($args|group|? C* -eq 1|% N*)-join'*'|iex

Try it online!

where |? C* -eq 1 means |? Count -eq 1 and |% N* means |% Name.


PowerShell, 45 bytes

$p=1;$args|group|? C* -eq 1|%{$p*=$_.Name};$p

Try it online!

Mathematica, 40 bytes

f[l_]:=Times@@(If[Count[l,#]<2,#,1]&/@l)

You can try it online!

C (gcc), 46 \$\cdots\$ 43 42 bytes

Saved 2 bytes thanks to 79037662!!!

f(a,b,c){a=a^b?a^c?b^c?a*b*c:a:b:b^c?c:1;}

Try it online!

J, 10 bytes

*/@-.}./.~

Try it online!

     }./.~  group by value and remove one from each group
   -.       set subtract from input
*/          product

JavaScript (ES6), 38 bytes

(a,b,c)=>a-b?b-c?c-a?a*b*c:b:a:b-c?c:1

Try it online!


JavaScript (ES6), 53 bytes

Takes input as [a,b,c].

A=>[[a,b,c]=A,1,a-b?a-c?a:b:c,a*b*c][new Set(A).size]

Try it online!

Commented

A =>                // A[] = input
  [                 // lookup table:
    [a, b, c] = A,  //   set size = 0 --> impossible, so use this slot
                    //   to split A[] into 3 distinct variables
    1,              //   set size = 1 --> return 1
    a - b ?         //   set size = 2 --> if a is not equal to b:
      a - c ?       //     if a is not equal to c:
        a           //       return a
      :             //     else:
        b           //       return b
    :               //   else:
      c,            //     return c
    a * b * c       //   set size = 3 --> return a * b * c
  ]                 //
  [new Set(A).size] // index into lookup table = size of the set

GolfScript, 31 bytes

...{{*}*}:m;m\.|m/-m\.|,1=\1\if

This was... a lot more difficult than I thought it would be. Can be optimized. So much so, that I don't really want to give this much of an explanation.

Here's the process:

Take your input array and make 3 more copies of it. Make a function m, which multiplies the elements in an array together. Do that to the first array, then eliminate dupes from a second (keeping one of each). Perform m on it, then divide it from the first number. You should have the duplicate number (if there's only one pair dupe). Remove it rom your array, then return the last number. If the "suspected dupe" is 1, then just multiply again and output. If, when you remove all of the "suspected dupe"s, you're left with an array of size 1, just output 1 instead.

This was incredibly and probably needlessly complicated, but I couldn't find any good GolfScript shortcuts besides the multiplication bit. PITA.

Try it online, I guess

Perl 5 -MList::Util=product -apl, 45 44 bytes

@FryAmTheEggman saves a byte

$_=product(grep{$t=$_;2>grep$t==$_,@F}@F)||1

Try it online!

PowerShell, 97 bytes

param($n)$a,$b,$c=$n|group;(($n-join'*'|iex),(($a,$b|?{$_.count-eq1}).name,1)[$a.count-eq3])[!$c]

Try it online!

Not terribly impressive, but given that PowerShell doesn't have a ternary operator like JavaScript, nor the same for structure as Python, I don't think this is too bad.

We take input $n as an array, then feed that into Group-Object, which stores the (potentially) three values into $a, $b, $c. Then we use array-indexing as a pseudo-ternary. We work "backwards" on the function definition given in the challenge, starting from the bottom. If we have a $c, then we have three unique values, so we -join $n with * and iex it (similar to eval). Otherwise, we have at least a duplicate, so we re-index whether $a's .count is -equal to 3. If it is, then all three values are the same, and we output 1. Otherwise, we pull out the lonely value (i.e., its .count is -equal to 1) and output its .name. In any case, the result is left on the pipeline and output is implicit.

Burlesque, 24 bytes

psJ{{1j}qfcqpd}M-jNBL[!!

Try it online!

ps     # Parse to list
J      # Duplicate
{
 {1j}  # Push 1 & swap
 qfc   # Find least common element
 qpd   # Product
}M-    # Create array applying each function to make each element
       # {{Original list}, 1, least common, product}
jNB    # Remove duplicates from original list
L[     # Find length
!!     # Select that element from the array 
       # (zero indexed, hence the push swap to fill zero)

Burlesque, 31 bytes

psJU_qpd{f:{-]1==}fe[~}IEisq1if

Try it online!

Can probably be golfed further.

ps      # Parse to array
JU_     # (Non-destructive) is each element unique?
qpd     # boxed product
{
 f:     # Frequency (returns {{count val} ...})
 {
  -]1== # Count == 1
 }
 fe     # Find element where
 [~     # Take the tail
}
IE      # If unique then product, else find single
is      # Is an error (i.e. single not found)
q1      # boxed 1
if      # If error, push 1

05AB1E, 3 bytes

¢ÏP

Try it online!

¢       # count occurences of each number
 Ï      # keep only those where the count is 1
  P     # product (1 if the list is empty)