[Question]
  [
iOS 11 has a bug [that makes the result of 1+2+3 to be 24](https://www.reddit.com/r/apple/comments/782250/try_quickly_typing_1_2_3_into_the_ios_11/?sort=old&sh=63028759&st=J93B9RWJ). This is related to the animation speed, but anyway:
The task is to make `1 + 2 + 3 == 24`. But only that. So you should provide a function that correctly sums most sequences but returns `24` when the arguments are `1`, `2` and `3` in any order.
Example inputs:
```
1 2 => 3
3 4 => 7
1 2 3 4 5 6 7 8 9 => 45
3 2 1 => 24
2 1 3 => 24
1 1 => 2
1 2 3 => 24
40 2 => 42
1 2 2 4 => 9
1 2 3 4 1 2 3 => 16
1 => 1
1 23 => 24
0 1 2 => 3
3 2 3 => 8
```
Input can be in any format as long as your code accepts any number of arguments.
* Support for negative numbers isn't required (all non negative numbers are required to work, that includes 0)
* We assume correct input
---
Differences from [another similar question: "What do you get when you multiply 6 by 9? (42)"](https://codegolf.stackexchange.com/questions/124242):
* In this case your function is required to accept **any** number of arguments. The old question specifies exactly 2.
* In this case order doesn't matter, while the old question specified that order `6 9` is required and `9 6` should be evaluated correctly.
  
[Answer]
# Java 8, ~~109~~ ~~106~~ ~~101~~ ~~90~~ ~~75~~ ~~74~~ ~~71~~ 66 bytes
```
a->{int s=0,p=0;for(int i:a){s+=i;p|=1<<i;}return s<7&p==14?24:s;}
```
-12 bytes thanks to *@OlivierGrégoire*.  
-31 bytes thanks to *@Nevay*.
**Explanation:**
[Try it here.](https://tio.run/##jZCxTsMwEIb3PsVNKBFXK0kDpXUMT0CXjojBdV3kkjpW7FRCIc8eLi0DC3Il25LPn7/7dUd5lvPGaXvcf65GVUvv4VUa288AjA26PUilYTNdLwVQCZ2MMZApp@JAm5YPMhgFG7AgYJTz535ivcjQiYwfmnb6BWYt097fC8Pdt8iryvCh1aFrLfhqeeeEyMuXolx7Poz86nXdribvr/7cmD2cKF2yDa2xH2/vlOIabfvlgz6xpgvM0VOobWKZSnIs0kvOf4kFlhGCHEgUPuAjLvEJV1FjgXmEIQIX0b75LckiTJlFRzBpipvH8KfpMBvGHw)
```
a->{                  // Method with integer-array parameter and boolean return-type
  int s=0,            //  Sum-integer, starting at 0
      p=1;            //  Product-integer, starting at 1
  for(int i:a){       //  Loop over the input-array
    s+=i;             //   Add current item to sum
    p|=1<<i;          //   Take 1 bitwise left-shifted with `i`, and bitwise-OR it with `p`
  }                   //  End of loop
  return p==14        //  If `p` is now exactly 14 (`0b1110`)
    &s<7?             //  and the sum is 6 or lower:
     24               //   Return 24
    :                 //  Else:
     s;               //   Return the sum
}                     // End of method
```
(Inefficient) proof that only `[1,2,3]` (in any order) will be the possible results when `p` is `0b1110` (`p==14`) and the sum is below 6 or lower (`s<7`): [**Try it here.**](https://tio.run/##jZG9TsMwFEZn/BRXnhyZVhTB5HpgQEww0BExOLZbpbRJVDuVEOTZQ5Imjpuflgz3OvaJ7/mUrTiKWZLqeKu@ikLuhDHwKqL4BwGkWbiLJBgrbNmOSaRgXx6RlT1E8ebjE8RhY4KKBIhiC@9Pby/PwOH@kdV76@RAqn3BZ/URA7Hk7YrS5suOCx0XOi70uI6UjpSOlDV500HKQcpB6uw6/0rtaO1oPaBPQQ0XNKSSKqrZyHHKSfnc/ZLFcimCoO5h02XTVdN1MLhhTVLOFw@DyQCrb2P1fp5kdp6Wv8DuYiIovsWlTFVlXVVdNcVATLbnmBqKAzwYk6Ppt7OMDI3muxav99lUqP9GuhTGl/fXXgyGhhGmEpyx497Xrad9O8Nu5UwZ6ln2JT1gTO2S2JRSq9H2RoYhX6T1cLvD6eOzx6eeZlU1R3lR/AE)
> 
> `p==14` (`0b1110`) evaluates to true iff the input values modulo 32 cover the values `1`, `2` and `3` and contain no other values (`p|=1<<i`) (each value has to occur 1+ times). The sum of input that matches `p==14` will be larger than `6` for any input except `1,2,3` (`s=a*1+b*2+c*3+u*32` with `a>0,b>0,c>0,u>=0`).  
> 
> *@Nevay*
> 
> 
> 
---
Old **71 bytes** answer:
```
a->{int s=0,p=1;for(int i:a){s+=i;p*=i;}return a.length==3&p==s?s*4:s;}
```
Proof that for any three given non-zero natural numbers, only `[1,2,3]` (in any order) will have a sum equal to its product (`1+2+3 == 1*2*3`) (with a positive sum):  
[*When the sum equals the product* by Leo Kurlandchik & Andrzej Nowicki](http://www-users.mat.umk.pl/%7Eanow/ps-dvi/si-krl-a.pdf)
(Inefficient) proof that only `[1,2,3]` (in any order) and `[0,0,0]` will be the possible results with non-negative numbers and a length of 3: [**Try it here.**](https://tio.run/##XY8xD4IwEIV3fsXFCawanLGDg3HSQUbjcK1AitA2tJIYw2/HVo0Cy93lve9e7kpscal0Jsvrre95hcbAAYV8BgD6zirBwVi0rrVKXKF2VpjaRsjifAFsChN5EkBIC6ftcb8DCus4jpO3mqsm9A7SOAHc0DfhJkK@a3@EeYT9EDZA/hD3EP9BfAR9jjAUCSM8mcia4pzNx3IeGkr1KAEgfRib1St1tyvt3rSVDJHMFjMX6iuPhhFdMJ0@3dcu6Pr@BQ)  
So `s*4` will becomes `6*4 = 24` for `[1,2,3]`, and `0*4 = 0` for `[0,0,0]`.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~11~~ 10 bytes
```
St3:X=6*+s
```
[Try it online!](https://tio.run/##y00syfn/P7jE2CrC1kxLu/j//2hjHUMdo1gA "MATL – Try It Online") or [verify all test cases](https://tio.run/##y00syfmf8D@4xNgqwtZMS7v4v0vI/2hDHQWjWK5oYx0FEyAF4ukogDg6CqY6CmY6CuY6ChY6CpYQJUA5QyALRAFVQdQbIrQBWSYGEPMgIkaYpiKUwjQaxwIA "MATL – Try It Online")
**Explanation**
```
        % implicit input [3,1,2]
S       % sort
        % STACK: [1,2,3]
t       % duplicate elements
3:      % push range 1..3
        % STACK: [1,2,3], [1,2,3], [1,2,3]
X=      % true if arrays are numerically equal
        % STACK: [1,2,3], 1
6*+     % multiply result of comparison by 6 and add to the original array
        % STACK: [7,8,9]
s       % sum
        % (implicit) convert to string and display
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
Os{3LQi4*
```
Explanation:
```
Os{         Get the sum of the input, and then get the sorted input list
     Qi     If it is equal to...
   3L       [1, 2, 3]
       4*   Then multiply the sum by four.
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fv7ja2Ccw00Tr//9oQx0Fw1gA "05AB1E – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
3R⁼Ṣ4*×S
```
[Try it online!](https://tio.run/##y0rNyan8/9846FHjnoc7F5loHZ4e/P///2hDHQUjHQXjWAA "Jelly – Try It Online")
[Answer]
# [Haskell](https://www.haskell.org/), 37 bytes
```
f[a,b,c]|2^a+2^b+2^c==14=24
f l=sum l
```
[Try it online!](https://tio.run/##dY/BDoIwEETvfMUcvLkHWwrIYb@EQFLQRmJBI3rz32tpgpFQD3vZNzO7c9HT9Wytc6bS1FJXv2Wj97Jp/XTMQrFUiYHl6TXAukH3IxinWwLcH/34xA4GlSDIGsxI1/uUoMK@2OoJMyVkhJxQEI6EMohVtknxahGY/2bFZuCTokx8TdHrUY86LFVU1CWXRuX/Rr/5Incf "Haskell – Try It Online")
We use pattern matching to catch the exceptional case.
Haskell doesn't have sorting built-in. The equality `2^a+2^b+2^c==14` is satisfied only by `[a,b,c]` a permutation of `[1,2,3]` among non-negative integers. A shorter `a+b+c=a*b*c` almost works, but is satisfied by `[0,0,0]`, and appending the check `,a>0` makes it 1 byte longer.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 13 bytes
```
stGp=18*Gda*+
```
[Try it online!](https://tio.run/##y00syfn/v7jEvcDW0ELLPSVRS/v//2izWAA "MATL – Try It Online")
It's two bytes longer than the other MATL answer, but it uses a completely different (and IMO more interesting) approach, so I figured it's worth posting.
### Explanation:
This solution uses the fact that: 
> 
> The sum and product of an array with three elements are only equal if the array is a permutation of `1,2,3`. 
> 
> 
> 
This takes the input, calculates the sum `s`, and duplicates it `t`. It then checks if the sum equals the product `Gp=`. We multiply the boolean `1/0` by 18, `18*`, and checks if there are non-identical values in the vector `da*` (again, multiply by a boolean `any(diff(x))`. We then multiply the two add the last number to the original sum.
A step by step explanation:
Assume the input is `[1, 2, 3]`:
```
s                              % Implicit input, calculate the sum
                               % 6
 t                             % Duplicate the sum:
                               % 6, 6
  G                            % Grab input
                               % 6, 6, [1,2,3]
   p                           % Calculate the product
                               % 6, 6, 6
    =                          % Check if the last two elements are equal
                               % 6, 1 (true)
     18*                       % Push 18, multiply by the last number
                               % 6, 18
        G                      % Grab input
                               % 6, 18, [1,2,3]
         d                     % Calculate the difference between each element
                               % 6, 18, [1,1]
          a                    % any non zero elements?
                               % 6, 18, 1 (true)
           *                   % Multiply last two numbers
                               % 6, 18
            +                  % Add numbers. Result: 24
```
[Answer]
# [Python 2](https://docs.python.org/2/), 39 bytes
```
lambda*a:sum(a)+18*(sorted(a)==[1,2,3])
```
[Try it online!](https://tio.run/##FcqxDsIgFEDRuXzFG6G@QVo1pgljXV3c1AEtTUlaIA@I9uuxjufmhjVN3jVlVI8y6@U16Fp3MS9ci5081zx6SmbYpNRdYoPtU5REa8eqz2RnAzfKZkMVyLoEI6@tCzlxIZj5vk1I0F8vPZGnbQo6xiIRGoSWHRCOCCe2R/inHw "Python 2 – Try It Online")
Uses an alternate method of adding 18 if the sorted input is `[1, 2, 3]` to beat the [other Python answer](https://codegolf.stackexchange.com/a/146185/60919) by a byte.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 34 bytes
```
@(x)sum(x)+isequal(sort(x),1:3)*18
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0KzuDQXSGpnFqcWlibmaBTnF5UA@TqGVsaaWoYW/9M0og11jHSMYzW5gEwjHUMY0xjINIIw4Qy4OrAWHRNkDpIpUFkdUx0zHXMdCx1LoPB/AA "Octave – Try It Online")
or 
```
@(x)(s=sum(x))+18*~(s-6|prod(x)-6)
```
[Try it online!](https://tio.run/##y08uSSxL/Z9mq6en999Bo0JTo9i2uDQXyNDUNrTQqtMo1jWrKSjKTwGK6Jpp/k/JLC7QSNOINtQx0jGO1dTkggmYAAUMkQWAKoDc/wA)
or
```
@(x)(s=sum(x))+18*~(s-prod(x)|s-6)
```
This is shorter than the approach others use: `@(x){24,sum(x)}{2-isequal(sort(x),1:3)}`.
**Explanation:**
It takes the sum of the vector, and adds 18 if the sorted vector is equal to `1,2,3`. This will give `6+18=24` if the vector is a permutation of `1,2,3`, and just the sum of the vector if not.
[Answer]
# PHP, 116 bytes
This is my first attempt at a golfing challenge ever, AND it's PHP, a language which apparently sucks at golfing since I rarely see it here, so ... uhm, I tried?
```
<?php
//call as var/www/html/cg_ios.php --'1 2 3 4 5'
$i=$argv[1];$a=(explode(' ',$i));echo((($b=array_sum($a))==6&&count($a)==3&&in_array(3,$a)&&!in_array(0,$a)?24:$b));
```
Note: I did not include the comment into the bytecount.
### Ungolfed
It's nothing special tbh:
```
$i=$argv[1];             //Read the input from the command line
$a=array_filter($c=explode(' ',$i)) //Split the input string into an array, use Whitespace as delimiter
                         //also, remove all 0 from the array, since they are not important at all
echo(                    //print the result
    ($b=array_sum($a) == 6  //If The SUM of the Array is 6 ...
        &&               //... AND ...
    (count($c) == 3)     //... the array has exactly 3 values ...
        &&               //... AND ...
    in_array(3,$a)       // ... the array contains the value 3 ...
        &&               // ... AND ...  
    !in_array(0,$a)      //... the array contains no zeros
        ?
    24                   //print 24
        :
    $b));     //print the sum of the array values we saved earlier
```
If you want to test this in PHPFiddle and not on console, you can obviously replace `$i` with anything you'd like.
Thanks to Olivier Grégoire who made me aware of the string combination `[0,3,3]` which returned 24 before and also helped me saving a few chars by storing the `array_sum` and returning that instead of running the function again.
[Answer]
# R, ~~47 bytes~~ ~~34 bytes~~ 36 bytes
```
x=scan();all(sort(x)==1:3)*18+sum(x)
```
[Try it online!](https://tio.run/##fYvBCgIhFEX37yuENs96i566iMKPERlhwBwaNQaibzcJGVq1O/eee9fWNpu9SyhvLkbMy1pwk9byVcsjX0653ntuDAwKNEAQVoSafJmX1MXrz@ktDtOjzk8Xp1QgoEcmJeWXNJlB5ryXXZMerIh31r3n3w0ZGtv2AQ)
Sum the input and add 18 if the input set is 1:3.  
Thanks to @mlt for golfing off 11 bytes.
Thanks to @Ayb4btu for identifying an error with the overgolfed code
[Answer]
# Javascript ES6, 39 bytes
Thanks to @Herman Lauenstein
```
a=>a.sort()=="1,2,3"?24:eval(a.join`+`)
```
```
f=a=>a.sort()=="1,2,3"?24:eval(a.join`+`)
console.log(f([1,2,3]));
console.log(f([1,2,3,4]));
```
# Previous answer
Javascript ES6, 66 bytes
```
a=>(n=[1,2,3],a.every(_=>n.includes(_))?24:a.reduce((x,y)=>x+y,0))
```
## Try it
```
f=a=>(n=[1,2,3],a.every(_=>n.includes(_))?24:a.reduce((x,y)=>x+y,0))
console.log(f([1,2,3]));
console.log(f([1,3,2]));
console.log(f([1,2,3,4]));
```
[Answer]
## Swift, 67 Bytes
```
func z(i: [Int])->Int{return i.sorted()==[1,2,3] ?24:i.reduce(0,+)}
```
Could make it to 27 bytes with extensions on [Int], but that would be cheating :(
[Answer]
# Mathematica, 28 bytes
```
If[Sort@#=={1,2,3},24,Tr@#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/DfMy06OL@oxEHZ1rbaUMdIx7hWx8hEJ6TIQTlW7X9AUWZeiYJDWjRUKvY/AA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# J, 17 bytes
*-6 bytes thanks to Frowny Frog*
```
+/*1+3*1 2 3-:/:~
```
Sum all the numbers `+/` and multiply the result by (pseudocode) `1 + 3*(is123 ? 1 : 0)`. That is, return the results unchanged unless the sorted list is `1 2 3` in which case we multiply the result by 4.
[Try it online!](https://tio.run/##VYo7DsIwEAV7n2KUJiIBgr02n5V8GhQL0VCkTq5uTEyKFK@YN/POaSIqF8pyP3S2l87ikJMOuuSDac60KWrLkVlJkzHj8/VBiCRKWfG2ouAr@rDp30fgWoo7j2qd/9cOu3sKI/kL "J – Try It Online")
### original answer
```
+/`(24"_)@.(1 2 3-:/:~)
```
Check if the sorted input is `1 2 3` -- if yes, invoke the constant function 24 (`24"_`); if not, return the sum `+/`
[Try it online!](https://tio.run/##VYq9DoIwGEX3PsUJCzTyI20R/ZImvokkxMa4MDDDq9dqdXC4w7nnPGNY8cKRtHjopsq44qavbdVjsI10suuoVdFSBi8lNZsQVqXu82PB4gmkNOP4QYvL6Iaffn8MnFJx5pKtcd/a0P89ibHxBQ "J – Try It Online")
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 57+18=75 bytes
```
a=>a.OrderBy(x=>x).SequenceEqual(new[]{1,2,3})?24:a.Sum()
```
[Try it online!](https://tio.run/##lY5Ba4MwGIbPy6/4jglkAXWnOS1taWGwsYGHHYqHED9KQBM0SWsRf7uTFWG3udPLCw/P@yr3qGyHU3DanKG4OY9NSn438aZNmxJVS@fgcyDOS68VHINRL9r4U8lhjhxerdtWFWQwySyX4qOrsNvdaJ/lPRMFtgGNwkMbZE0NXk/lEPGYJyPbxE/PUhShoWxKyaK/WF3Bu9SGMjKQh701ztYovjrtcT6E9D53V8HiYunfaMyjtehsXQ3yhP/jRPSDjWScvgE "C# (.NET Core) – Try It Online")
+18 for `using System.Linq;`
[Answer]
# [Lua](https://www.lua.org), ~~116~~ 81 bytes
-7 bytes thanks to [Jonathan](https://codegolf.stackexchange.com/users/74172/jonathan-s)
Takes input as command line arguments
```
Z=0S={}for i=1,#arg do
j=arg[i]+0S[j]=0Z=Z+j
end
print(#S>2 and#arg<4 and 24or Z)
```
[Try it online!](https://tio.run/##yylN/P8/ytYg2La6Ni2/SCHT1lBHObEoXSElnyvLFsiIzozVNgiOzoq1NYiyjdLO4krNS@EqKMrMK9FQDrYzUkjMSwGptzEBsRSMTIBmRGn@///f8L/xfyMA "Lua – Try It Online")
# Explanation:
Works by creating an sparse array `S` and adding zeroes in the indices corresponding to the input values. If parameters are `3, 4, 7` the sparse array will only have numbers at those indices. With that array, we get it's length with the operator `#` that counts from index `1` up to the higher index that has a value in it, if this length is exactly `3`, it means that there were elements in the position `1`, `2` and `3` wich is what we're looking for. The length of the sparse array will be always between `0` and `N` where `N` is the number of parameters. So we just have to check if the length of both the parameters array and the sparse array is `3`.
[Answer]
# C++17, ~~56~~ 54 bytes
```
[](auto...i){return(-i&...)+4|(~i*...)+24?(i+...):24;}
```
[Try it online!](https://godbolt.org/g/cCqkC6)
Note that the function object created is usable at compile time, so the tests are performed by the compiler without having to run a program.
### Explanation:
```
[]             // Callable object with empty closure,
(auto...i)     // deduced argument types,
{              // and deduced return type
  return       //
      (-i&...) //   If the fold over the bitwise AND of the negation of each argument
    +4|        // is unequal to -4, or
      (~i*...) //   if the product of the bitwise complements of the arguments
    +24?       // is unequal to -24, then
      (i+...): //   return the sum of the arguments, otherwise
      24;}     //   return 24.
```
Proof that the only nonnegative `i...` for which `(-i&...)` equals -4 and `(~i*...)` equals -24 are the permutations of `1, 2, 3`:
We first observe that since `-0` = `0`, if any `i` = `0` then `(-i&...) = 0`, so we conclude that all the `i` are positive.
Now, note that in 2's complement, `-i` is equivalent to `~(i - 1)`, and `~i` is equivalent to `-(i + 1)`. Applying De Morgan's rule, we find that `(-i & ...)` = `~((i - 1) | ...)` = `-(((i - 1) | ...) + 1)`, so `((i - 1) | ...) = 3`; similarly, `-1 ** n * ((i + 1) * ...) = -24`, so `n` is odd and `((i + 1) * ...) = 24`.
The prime factors of 24 are 2\*\*3 \* 3, so `n` <= 4. If `n` = 1, we have `i - 1 = 3` and `i + 1 = 24`, so `n` = 3. Write the `i` wlog as `a <= b <= c`, then clearly `a` = 1 as otherwise `(a + 1)(b + 1)(c + 1)` >= 27. Also `c` <= 4 as otherwise `(a - 1)|(b - 1)|(c - 1)` >= 4. `c` cannot be 4 as 5 is not a factor of 24, so `c` <= 3. Then to satisfy `(a - 1)|(b - 1)|(c - 1) = 3` c = 3, b = 2 as required.
[Answer]
# [R](https://www.r-project.org/), ~~55~~ ~~45~~ ~~54~~ ~~49~~ ~~57~~ ~~54~~ 48 bytes
Saved many ~~bytes and~~ incorrect solutions thanks to Ayb4btu.
Saved ~~3~~ 9 bytes thanks to Giuseppe. I keep learning new ways to abuse the fact that `F==0`. 
```
"if"((s=sum(x<-scan()))-prod(x)|sum(x|1)-3,s,24)
```
[Try it online!](https://tio.run/##dY3dCoJAFITvfYrFbvbAEfaPtSgfRkxBKC1XQ8iefdt2VSzo7sw3M2c6a@O6iik1mRmudDwlpsgbCgDJrWvPdITJ84lDItGgUGA5EURGUZVVQ1P0ddu41HPuw9G/M3/bL7Ij5X2oH/mlbHr3hRaUowAgWea@fqREFWTqpWKLrcQSRxmIUJ4I5D9Eugz/Ir6FCjdtrslqiWX04BDzF/MmQwarVMFRbOltV7U/9WxtdtIV6QD29g0 "R – Try It Online")
The other R answer won in the end.
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~136~~ ~~131~~ ~~125~~ ~~97~~ ~~91~~ ~~83~~ 81 bytes
Thanks to @landfill babby, and @ceilingcat (of course we're not using c anymore)
```
r,t;main(i,v)int**v;{for(;*++v;t|=1<<i)r+=i=atoi(*v);printf("%d",r>6|t-14?r:24);}
```
[Try it online!](https://tio.run/##Dco7CoAwDADQuwhCfw614mCsnkUqlQx@CKGLevbom19qtpREyDHsCx4KXdF4sDEF7nySAmNtAX6iH0fUZCPGhU9Upmi46J9ZVfVaOZr6hxvfzTS0nYZXRIJ4CR8 "C (gcc) – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina), 21 bytes
```
O`
^1¶2¶3$
24
.+
$*
1
```
[Try it online!](https://tio.run/##K0otycxL/K@qEZyg898/gSvO8NA2o0PbjFW4jEy49LS5VLS4DP//N9Qx4jLWMeEC0jpAWsdUx0zHXMdCxxIoaqRjyAXEOsZAWUOICi4TA6AGENMISROYBgA "Retina – Try It Online")
Input is linefeed-separated, but the test suite uses comma-separation for convenience.
### Explanation
```
O`
```
Sort the numbers (lexicographically, actually, but we only care about the case that the inputs are `1`, `2`, `3` in some order, where that doesn't make a difference).
```
^1¶2¶3$
24
```
If the input is `1,2,3` (in some order), replace it with 24.
```
.+
$*
```
Convert each number to unary.
```
1
```
Count the number of `1`s, which adds the unary numbers and converts them back to decimal.
[Answer]
# [Haskell](https://www.haskell.org/), 44 bytes
```
f a|sum a==6,product a==6,a<[6]=24|1<2=sum a
```
[Try it online!](https://tio.run/##dY87DoMwEET7nGKKlFvExpggsSdBFFYICgo/8em4uwFHREE45c6bmdW8zPB@VpW1Bcw8TDUMs6aub/PpMX4Ok6Q6Y6lmkUh2FlubsgEjby9A15fNiCsKpIIgMzAjOOoBQTk9OvsJGyWEBE2ICHdC7MwqPLWsbuGYVEe2gbXJy8Q35P3uzajbPkV5U3JfFP9f9NsvtF0A "Haskell – Try It Online")
The permutations of `[1,2,3]` are the only partitions of `6` whose product is `6`, barring `6` itself. (This assumes the inputs are non-negative, which seems to be the case for all the test cases… I’ve asked the OP about this.)
[Answer]
## **PL/SQL - ~~135~~ 123 Bytes**
Assuming i as an integer array input of any size:
```
if (select sum(s) = exp(sum(ln(s))) from unnest(i) s) then
    return 24;
else
    return (select sum(s) from unnest(i) s);
end if;
```
[Answer]
# [Jq 1.5](https://stedolan.github.io/jq/), 35 bytes
```
if[1,2,3]==sort then 24else add end
```
Assumes input is an array e.g. `[2,1,3]`
[Try it online!](https://tio.run/##VY7LDoIwEEXX5SuauJ0m9gHIAn@EsCChRgxpEUrc@O3WodRUlvfcM4/H0zccRAuEkBOtr1RmjQSVcpltPSCDHAoo4QIVtqFT@SYL4JseiFBZgxnkgfDdiCAuPBjq/P@Dio7YHwmsSn/8xgPnBRZplAdNtiQtf/vhFk/W9WJnR91dG2z0uGja9T3Vpvf@Yyc3WLN4xsw6jmww0@owzN2L2dVh@AI "jq – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 9 bytes
```
?K24Σ=ḣ3O
```
[Try it online!](https://tio.run/##yygtzv7/397byOTcYtuHOxYb@////z/aWMdIxzAWAA "Husk – Try It Online")
### Explanation
```
?K24Σ=ḣ3O
        O    Sort the input
?    =ḣ3     If it is equal to [1,2,3]:
 K24           Return 24
             Else:
    Σ          Return the sum of the input
```
### Previous solution
Gives the wrong result to [2,2], and probably other inputs too, but it was more interesting.
```
?ṁD→E§eΠΣ
     §eΠΣ    Build a two-element list with the product and sum of the input
?   E        If the two elements are equal:
             (true for any permutation of [1,2,3] and the list [0,0,0]
 ṁD            Double both elements and sum them
               (This is 4 times the sum: 24 for permutations of [1,2,3], 0 for [0,0,0])
             Else:
   →          Return the last element (the sum)
```
[Try it online!](https://tio.run/##ASAA3/9odXNr//8/4bmBROKGkkXCp2XOoM6j////WzMsMiwxXQ "Husk – Try It Online")
[Answer]
# [Pushy](https://github.com/FTcode/Pushy), 12 bytes
```
gF3RFx?18;S#
```
[Try it online!](https://tio.run/##Kygtzqj8/z/dzTjIrcLe0MI6WPn///@GOgpGOgomAA "Pushy – Try It Online")
This works by sorting the input and, if it is equal to `[1, 2, 3]`, appending 18. Then, the sum is calculated and printed, yielding 24 is 18 was appended, and the normal answer otherwise.
```
         \ Implicit: Input on stack.
g        \ Sort input ascendingly
F3RF     \ On auxiliary stack, push range(3) -> [1, 2, 3]
x?       \ If the stacks are equal:
  18     \    Append 18 to the input
;
S#       \ Print sum of input.
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
```
?qS3SK24s
```
**[Verify all the test cases.](https://pyth.herokuapp.com/?code=%3FqS3SQ24s&test_suite=1&test_suite_input=%5B1%2C2%2C3%5D%0A%5B2%2C1%2C3%5D%0A%5B3%2C1%2C2%5D%0A%5B1%2C2%5D%0A%5B2%2C3%5D%0A%5B1%2C2%2C3%2C4%5D%0A%5B1%2C2%2C3%2C1%2C2%2C3%5D%0A%5B1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%5D&debug=0)**
[Answer]
# [Python 2](https://docs.python.org/2/), ~~41~~ 39 bytes
-1 byte thanks to [caird](https://codegolf.stackexchange.com/users/66833/caird-coinheringaahing)
-1 by inspiration from [FlipTack's answer](https://codegolf.stackexchange.com/a/146197/66418)
```
lambda*a:sum(a)*4**(sorted(a)==[1,2,3])
```
[Try it online!](https://tio.run/##Fcq9DsIgFEDhuTzFHYHcoaXVoQljXV3c1AEtTUn6Qy4Q7dMjjt/J8Uec903lST/yYtbXaKTpQ1q5EbKTkoedoh2LtL43qLB9ihzp6Fn1md1i4UbJFlSe3BZh4tJtPkUuBLPft/URhutlINqpTN6EkBsEhdCyDuGEcGY1wj/9AA "Python 2 – Try It Online")
### Alternative 39 bytes solution
```
lambda*a:sum(a)<<2*(sorted(a)==[1,2,3])
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~10~~ 9 bytes
```
Ṣ24S⁼?3R¤
```
[Try it online!](https://tio.run/##y0rNyan8///hzkVGJsGPGvfYGwcdWvL///9oQx0FIx0F41gA "Jelly – Try It Online")
-1 byte thanks to [Erik](https://codegolf.stackexchange.com/users/41024/erik-the-outgolfer)
Alternative (by [Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder)), also for 9 bytes:
```
3R⁼Ṣ×18+S
```
[Try it online!](https://tio.run/##y0rNyan8/9846FHjnoc7Fx2ebmihHfz///9oQx0FIx0F41gA "Jelly – Try It Online")
## How it works
```
Ṣ24S⁼?3R¤ - Main link. Argument: l (list)
Ṣ         - Sort
     ?    - Ternary if statement
    ⁼     -  Condition: Is l equal to...
      3R¤ -    [1, 2, 3]
 24       -  If condition: Return 24          
   S      -  Else: Return the sum of the list
```
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 9 bytes
Different aproach from the other Pyth answer.
```
*sQ^4qS3S
```
### Explanation:
A port from my Python answer
```
*sQ^4qS3SQ  # Full program (Q at the end is implicit and represents the input)
*           # A * B where A and B are the next two lines
  sQ        # Sum elements of input
  ^4        # 4 to the power of:
    qS3SQ   # Compares sorted input to [1, 2, 3] and returns 0 or 1
```
[Try it online!](https://tio.run/##K6gsyfj/X6s4MM6kMNg4@P//aEMdIx3jWAA "Pyth – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 44 bytes
```
param($a)($a-join'+'|iex)+18*!(diff(1..3)$a)
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVRE4h1s/Iz89S11WsyUys0tQ0ttBQ1UjLT0jQM9fSMNYFK/v//76BhqGOsY6QJAA "PowerShell – Try It Online")
Similar algorithm to the Python and JavaScript answers. Takes input as a literal array `$a`. Then immediately sums `$a` together, which forms the left-hand operator of the `+`.
The right-hand is the `diff` (alias for `Compare-Object`) of `1,2,3` and `$a` -- this is either an empty array if they are equal, or a non-empty array of the different items if they are not equal -- enclosed in a Boolean-not. So, if they are equal, that makes the empty array (a falsey value) into `$true`.
That's then multiplied by `18` which implicitly casts `$true` to `1` and `$false` to `0`. So the right-hand side will be `18` if the arrays are the same, and `0` otherwise. That gives the correct result of `24` if the input array is `1,2,3` in any permutation, and the summation of the input array otherwise.
]