| Bytes | Lang | Time | Link |
|---|---|---|---|
| 041 | JavaScript Node.js | 240202T110903Z | l4m2 |
| 007 | Uiua SBCS | 240202T104754Z | chunes |
| 118 | Pascal | 230721T145513Z | Kai Burg |
| 004 | Thunno 2 | 230721T064759Z | The Thon |
| 010 | Vyxal | 210711T111520Z | Wasif |
| 100 | C clang | 210606T124525Z | Stack Ex |
| 4812 | MMIX | 210606T020805Z | NoLonger |
| 039 | Scala | 210605T202959Z | cubic le |
| 020 | Factor + sets.extras math.unicode | 210605T195854Z | chunes |
| 011 | Stax | 210131T152251Z | Razetime |
| 006 | Brachylog | 210131T142257Z | Unrelate |
| 045 | TI BASIC | 200212T154134Z | TiKevin8 |
| 013 | Stax | 200220T181953Z | Nanajnai |
| 7271 | PHP | 200210T184550Z | Guillerm |
| 9279 | PHP | 200213T154142Z | 640KB |
| 155 | SQL | 200213T023742Z | Forty3 |
| 027 | Perl 6 | 200213T010708Z | nwellnho |
| 043 | Kotlin | 200212T171758Z | Quinn |
| 060 | C# | 200211T192116Z | user9206 |
| 036 | R | 200212T075917Z | Criminal |
| 042 | Excel Version 1911 | 200210T201925Z | emegolf1 |
| 037 | R | 200210T231946Z | Robin Ry |
| 178 | Whitespace | 200211T150305Z | Kevin Cr |
| 060 | Excel | 200211T142303Z | Wernisch |
| 074 | Racket | 200211T122637Z | Galen Iv |
| 037 | Haskell | 200211T084018Z | xnor |
| 038 | Ruby | 200211T073722Z | G B |
| 048 | Python | 200211T052330Z | xnor |
| 010 | APL Dyalog | 200211T034329Z | Jo King |
| 031 | Wolfram Language Mathematica | 200211T020246Z | ZaMoC |
| 039 | Zsh | 200211T004303Z | GammaFun |
| 006 | Japt | 200210T182054Z | Shaggy |
| 061 | Python 3 | 200210T180701Z | RGS |
| 026 | Bash + GNU utilities | 200210T203203Z | Digital |
| 052 | Python 2 | 200210T223651Z | ovs |
| 051 | Retina | 200210T214751Z | Neil |
| 011 | Charcoal | 200210T212929Z | Neil |
| 006 | Jelly | 200210T194655Z | Jonathan |
| 044 | PowerShell | 200210T194532Z | mazzy |
| 040 | Mathematica | 200210T200839Z | RGS |
| 042 | C gcc | 200210T185241Z | Noodle9 |
| 010 | J | 200210T194028Z | FrownyFr |
| 038 | JavaScript ES6 | 200210T183049Z | Arnauld |
| 031 | GolfScript | 200210T190953Z | Mathgeek |
| 044 | Perl 5 MListUtil=product apl | 200210T180812Z | Xcali |
| 097 | PowerShell | 200210T184924Z | AdmBorkB |
| 024 | Burlesque | 200210T175313Z | DeathInc |
| 003 | 05AB1E | 200210T180547Z | Grimmy |
JavaScript (Node.js), 41 bytes
f=(a,b,c)=>a>f||f(b,c,[a])*(a-b&&a-c?a:1)
For shorter solution Arnauld has a 38 one
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
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
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);}
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
Factor + sets.extras math.unicode, 20 bytes
[ non-repeating Π ]
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Ü
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ˢ×
ᵍ 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
PHP, 72 71 bytes
sort($argv);[,$a,$b,$c]=$argv;echo$a-$b?$b-$c?$a*$b*$c:$a:($b-$c?$c:1);
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;
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])));
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;
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}
(Using a Pair as matcher compares only values and ignores the key.)
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])
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
- Saved 38 bytes due to inspiration from Grimmy's 05AB1E solution.
R, 40 37 bytes
-3 bytes by taking input with scan().
prod(unique(x<-scan())^2,1/x)^!!sd(x)
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.
- if all entries are different, then
unique(x)==x, so we are down toprod(x)^1 - if 2 entries are equal, then the corresponding value gets cancelled out between
unique(x)^2and1/x, so we are left with the sole "lonely" value - if all 3 entries are equal, then we have
(...)^0which is 1.
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))))
Haskell, 37 bytes
f l=product[x|x<-l,filter(==x)l==[x]]
Pretty straightforward -- filter for elements that appear only once and take the product.
Python, 48 bytes
lambda l:eval("(%sin[%s,%s]or %s)*"*3%(l*4)+"1")
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)
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)
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=⊢∘≢⌸
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
Zsh, 39 bytes
(){i=1
for n;((i*=${(M)#@:#$n}>1?1:n))}
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.
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.
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:
If all three numbers were identical, it evaluates this:
^.* $.(_If two numbers were identical, it evaluates this:
^.* $.(5*_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
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
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
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;}
J, 10 bytes
*/@-.}./.~
}./.~ 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
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]
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.
Perl 5 -MList::Util=product -apl, 45 44 bytes
@FryAmTheEggman saves a byte
$_=product(grep{$t=$_;2>grep$t==$_,@F}@F)||1
PowerShell, 97 bytes
param($n)$a,$b,$c=$n|group;(($n-join'*'|iex),(($a,$b|?{$_.count-eq1}).name,1)[$a.count-eq3])[!$c]
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[!!
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
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
¢ # count occurences of each number
Ï # keep only those where the count is 1
P # product (1 if the list is empty)