[Question]
  [
Write a program which finds the non-unique elements of an array of signed integers. The resulting array can be in any order.
Your answer may be a snippet which assumes the input to be stored in a variable (`d`, say) and evaluates to the correct result.
### Test Cases
Each test case is a single line in the format `input => output`. Note that other permutations of the output are valid as well.
```
[]                        => []
[-1, 0, 1]                => []
[1, 1]                    => [1]
[3, 0, 0, 1, 1, 0, 5, 3]  => [3, 0, 1]
[-34, 0, 1, -34, 4, 8, 4] => [-34, 4]
```
Order of the elements doesn't matter. 
This is code golf, so the shortest answer (in bytes) wins.
  
[Answer]
# [K5](http://johnearnest.github.io/ok/index.html), 5 bytes
Assuming the input is already in a variable called `d`,
```
?d^?d
```
Take the distinct elements (`?`) of d except (`d^`) the distinct elements of d (`?d`). Nicely symmetrical, no? This works because the "except" operator removes only the first occurrence of the right argument from the left argument.
More generally,
```
nu: {?x^?x}
```
In action:
```
  nu'(();-1 0 1;1 1;3 0 0 1 1 0 5 3;-34 0 1 -34 4 8 4)
(()
 ()
 ,1
 0 1 3
 -34 4)
```
## Edit:
If we wanted to preserve the order of the first occurrence of non-unique elements, we could reverse the source list before and after we remove the unique elements via except at the cost of 4 extra bytes:
```
  nu: {?|(|x)^?x}
  nu'(();-1 0 1;1 1;3 0 0 1 1 0 5 3;-34 0 1 -34 4 8 4)
(()
 ()
 ,1
 3 0 1
 -34 4)
```
[Answer]
# CJam, 10
Assuming the array is already in variable D (based on [this comment](https://codegolf.stackexchange.com/questions/60610/non-unique-elements/60612#comment145849_60613)):
```
D{De=(},_&
```
[Try it online](http://cjam.aditsu.net/#code=%5B-34%200%201%20-34%204%208%204%5D%3AD%3B%0AD%7BDe%3D(%7D%2C_%26)
**Explanation:**
```
D{…},   filter items of D based on the block
  De=   count occurrences in D
  (     decrement (resulting in true/false for duplicate/unique)
_&      remove duplicates from the results
```
Note: append a `p` if you want pretty printing, otherwise the resulting array is just printed out with no delimiters by default. That is acceptable since the question specifies the snippet only needs to "evaluate to the correct result".
## Standard input/output version, 13:
```
q~_{1$e=(},&p
```
[Try it online](http://cjam.aditsu.net/#code=q~_%7B1%24e%3D(%7D%2C%26p&input=%5B-34%200%201%20-34%204%208%204%5D)
**Explanation:**
```
q~      read and evaluate the input array
_       duplicate the array
{…},    filter items based on the block
  1$    copy the array
  e=    count occurrences
  (     decrement (resulting in true/false for duplicate/unique)
&       set intersection with the initial array (removes duplicates)
p       pretty print
```
[Answer]
## Haskell - 32
```
import Data.List;f l=nub$l\\nub l
```
Pretty short, even with the import. `a \\ b` removes the first occurrence of each element of `b` from `a`, and `nub` makes all elements of a list unique.
[Answer]
# Pyth, 7 bytes
```
S{.-Q{Q
```
[Try it online.](https://pyth.herokuapp.com/?code=S%7B.-Q%7BQ&test_suite=1&test_suite_input=%5B3%2C+0%2C+0%2C+1%2C+1%2C+0%2C+5%2C+3%5D%0A%5B-34%2C+0%2C+1%2C+-34%2C+4%2C+8%2C+4%5D)
### How it works
Pyth automatically stores the evaluated input in `Q` and prints all unused return values.
```
     {Q  Convert Q into a set. This removes duplicates.
  .-Q    Perform "bagwise" difference of Q and set(Q).
         This removes the first occurrence of all elements in Q.
 {       Convert to set to deduplicate.
S        Sort. Returns a list.
```
[Answer]
# SQL, ~~44~~ 42 bytes
```
SELECT*FROM D GROUP BY I HAVING COUNT(*)>1
```
I hope it is OK to assume the integers are stored in table D?
This will work in both SQLServer, PostgreSQL and possibly others. Thanks to @manatwork from the 2 bytes.
[Answer]
## Mathematica, ~~29~~ 26 bytes
Assuming that input is stored in `d`:
```
Select[d⋃d,d~Count~#>1&]
```
Otherwise, it's 29 bytes as an unnamed function:
```
Cases[#⋃#,n_/;#~Count~n>1]&
```
Here, `d⋃d` (or `#⋃#`) is a golfing trick to remove duplicates - by taking the set union with itself, Mathematica interprets the list as a set, removing duplicates automatically, while the actual union doesn't do anything.
Afterwards, both methods simply filter those elements which appear in the original list at least twice.
[Answer]
# JavaScript (ES6), 37 bytes
Run this in the JavaScript console:
```
e={};d.filter(x=>(e[x]=1+e[x]||0)==1)
```
[Answer]
# Matlab / Octave, 40
I'm assuming input values are real (not complex). The input is in a variable `d`.
```
unique(d(sum(triu(bsxfun(@eq,d,d')))>1))
```
[Try it online](http://ideone.com/w5OldL) in Octave.
[Answer]
## Python 3.5, 30
```
[x for x in{*d}if~-d.count(x)]
```
Uses Python 3.5's set unpacking. The `~-` subtracts 1, which takes a count of 1 to 0 which is Falsy.
This gives a list. If giving a set is OK, then we use a set comprehension, saving 1 char and not needing version 3.5:
```
{x for x in d if~-d.count(x)}
```
[Answer]
# PowerShell, ~~31~~ 29 Bytes
```
($d|group|?{$_.Count-1}).Name
```
Assumes that `$d` is already populated (as given) -- e.g., `$d=@(-34,0,1,-34,4,8,4)`.
Pipes the array into the `Group-Object` cmdlet, which groups like-items together and spits out an object that's essentially an array of arrays. We pipe that to a `Where-Object` (the `?` operator) that has `Count` greater than one (i.e., there are duplicates), and output the `.Name` of those items. Has a side bonus of preserving the initial ordering, too.
Edit - saved two bytes thanks to [Danko Durbić](https://codegolf.stackexchange.com/users/1308/danko-durbi%c4%87)
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~13~~ 9 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?")[SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set")
Anonymous tacit prefix function.
```
∊(⊂1↓⊣¨)⌸
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT////1FHl8ajribDR22TH3UtPrRC81HPjv9pj9omPOqb6hXs7/eoY4bGo94@IM/T/1FX86H1xo/aJgJ5wUHOQDLEwzNYE6gEqvh/moJ6dKw6F4jSNdRRMNBRMIRyDRFMY7AESA6MgAxTHQVjmDZjE5gcmAlEFkAyVh0A "APL (Dyalog Unicode) – Try It Online")
`(`…`)⌸` for each unique element (left argument) and the indices where it occurs (right argument), apply the following tacit function:
 `⊣¨` one of the left (the unique element) for each on the right (the indices)
 `1↓` drop one
 `⊂` enclose (prevents padding with zeros to create a non-ragged matrix)
`∊` **ϵ**nlist (flatten)
[Answer]
# Julia, ~~30~~ 29 bytes
```
∪(d[find(sum(d.==d',1)-1)])
```
`d.==d'` creates a symmetric matrix with the value at `i,j` being true if `d[i]==d[j]` and false otherwise. `sum`ming in one dimension and then subtracting 1 will produce zero if there's only one of the element and nonzero if there's more than one. `find` will obtain the indexes of the non-zero elements, which are then used to index the array `d` itself. `∪` (union) acts like `unique` when used in this way, removing the repeats.
Old solution:
```
∪(filter(i->sum(d.==i)>1,d))
```
Simple - for each entry, it checks if there's more than one of it in the array. Those for which there are more than one are returned by "filter", and then `∪` (union) acts like `unique` when used in this way, removing the repeats.
Note: originally had it as a function, but question allows array to be stored in a variable, for which I've chosen `d` as suggested in the question.
[Answer]
# Octave, 22 bytes
Based on [Luis Mendo's answer](https://codegolf.stackexchange.com/a/60613/9288).
```
d(sum(triu(d==d'))==2)
```
[Answer]
# R, ~~31~~ 24 bytes
Thanks to [flodel](https://codegolf.stackexchange.com/users/5163/flodel) for the 7 bytes.
Assuming the input is already in `d`.
### code:
```
unique(d[duplicated(d)])
```
edit: now it outputs correctly if there are more than 2 duplicates as pointed by [aditsu](https://codegolf.stackexchange.com/users/7416/aditsu).
[Answer]
# Mathematica, ~~31~~ 29
```
Cases[{s_,t_/;t>1}:>s]@*Tally
```
[Answer]
# Shell + GNU coreutils, 12
```
sort|uniq -d
```
### Test output:
```
$ printf "%s\n" -34 0 1 -34 4 8 4 | ./nonuniq.sh 
-34
4
$ 
```
[Answer]
# Pyth, 7 bytes
```
ft/QT{Q
```
Explanation:
```
ft/QT{Q
           Q = eval(input())
     {Q    set(Q) - deduplicate
f          filter - with T as the filter variable.
  /QT      count in Q of T
 t         minus 1.
```
The filter removes all elements that appear exactly once from the set of elements.
[Answer]
## LINQ,62 54 bytes
Kinda new here, but here goes nothing.
```
d.GroupBy(c=>c).Where(g=>g.Count()>1).Select(g=>g.Key)
```
[Answer]
# Python 2.7, ~~36~~ 42
```
list(set(filter(lambda x:d.count(x)>1,d)))
```
*edit* : surrounded the expression with list(..) in order to comply with the format required in the question
[Answer]
# K (not K5), 10 bytes
```
x@&1<#:'=x
```
Assumes input is in `x`. I thought it'd be fun to do a non-K5 answer!
[Answer]
# Python 3 - ~~33~~ 30 bytes
`{_ for _ in d if d.count(_)>1}`
Repl output, `d` as input.
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), 7 bytes
**Solution:**
```
&1<#:'=
```
[Try it online!](https://tio.run/##y9bNz/7/X83QRtlK3dZYR8EAjAzBCMgw1VEw/v8fAA "K (oK) – Try It Online")
**Explanation:**
```
&1<#:'= / the solution
      = / group, key => value (index)
   #:'  / count length of each group
 1<     / 1 less than 
&       / keys where true
```
[Answer]
# Haskell + [hgl](https://gitlab.com/wheatwizard/haskell-golfing-library), ~~[11](https://codegolf.stackexchange.com/revisions/256322/1)~~ 10 bytes
```
(!!1)~<<bg
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708I7E4OzUnZ2W0km6Ec0CAUuxN1czcgvyiEoXC0sSczLTM1BSFgKLUnNKUVC6oRABXmm3M0tKSNF2LVRqKioaadTY2SekQgZs2uYmZebYp-VwKCgVFCioKaQrRRgpWVgqeeSU6CsY6CiY6CgY6CoY6CpY6CkZgESOwoBmQEQsxY8ECCA0A)
## Explanation
* `bg` sort a list into lists of like values.
* `(!!1)` get the second value or `[]` if there is none.
We use `~<<` to glue these together, which basically acts as a concat map.
## Reflection
This works pretty well, but the operator precedence is killing me.
Both of the following work but requires the parens to prevent an error.
```
nb<(df^*nb)
nb<(fdf~<nb)
```
If the operator precedence was different both of these would be competitive with the first one actually saving bytes.
I don't know if that means the precedence is wrong, but it's worth noticing.
`(!!)` should have a prefix function, *and* a bunch of versions with the index prefilled. I noticed this earlier but still didn't fix it, and now it's coming back to haunt me.
[Answer]
## Mathematica, 23 bytes
With input stored in `d`:
```
Pick[#,#2>1]&@@@Tally@d
```
As a function, 24 bytes:
```
Pick[#,#2>1]&@@@Tally@#&
```
for example, with
```
d = {3, 0, 0, 1, 1, 0, 5, 3}
Tally@d
```
returns this:
```
   {{3, 2},
    {0, 3},
    {1, 2},
    {5, 1}}
```
(first element of each sublist is the element, second one is frequency of occurrence). Applying to this list `Pick[#,#2>1]&@@@` transforms it to
```
{Pick[3,2>1], Pick[0,3>1], Pick[1,2>1], Pick[5,1>1]}
```
And where the second argument of `Pick` evaluates to `True` the first argument is returned.
[Answer]
## Perl 6, 16 bytes
Assuming the list is stored in `$_` you could use any of the following snippets.  
( which was specifically allowed )
```
(--«.BagHash).Set.keys # 23 bytes
```
```
keys .Bag (-) .Set # 18 bytes
```
```
# U+2216 SET MINUS
keys .Bag∖.Set # 16 bytes in utf8
```
---
If you don't care that you get a Bag you could leave off `keys`.
```
$_ = [3, 0, 0, 1, 1, 0, 5, 3];
.Bag∖.Set ∋ 3 # True
.Bag∖.Set ∋ 5 # False
```
---
None of these have the limitation of only working on signed integers, or even just numbers for that matter.
```
say keys .Bag∖.Set given |(<a b c d a a c>), 1/3, 2/3 - 1/3;
# (a c 0.333333)
```
[Answer]
# Ruby, ~~30~~ 28 bytes
In [the Interactive Ruby Shell](http://ruby-doc.com/docs/ProgrammingRuby/html/irb.html):
```
d.select{|x|d.count(x)>1}|[]
```
Saved 2 bytes thanks to [Kirill L.](https://codegolf.stackexchange.com/users/78274/kirill-l)
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
u-u¹
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8X@pbumhnf///4@OjtWJ1jXUMdAxBDIMwaQxkAfk64BETXWMQQqMTcAiINpEx0LHJDYWAA "Husk – Try It Online")
```
u       # unique element of
 -      # set difference between
  u¹    # unique elements of input  
        # and input
```
[Answer]
# [Thunno](https://github.com/Thunno/Thunno) `D`, \$7 \log\_{256}(96) \approx\$ 5.76 bytes
Note: this only works on Thunno 1.1.3+
```
gc1>kZU
```
(No ATO link since that's on v1.1.0 at the moment)
[![Screenshot](https://i.stack.imgur.com/NAlyxm.png)](https://i.stack.imgur.com/NAlyx.png)
### Explanation
```
gc1>kZU   # Implicit input. The D flag duplicates it implicitly.
g   k     # Filter the input for elements where the following is truthy:
 c        #   The count of the element in the input
  1>      #   Is greater than 1
     ZU   # Deduplicate and output implicitly
```
[Answer]
# JavaScript, ~~35~~ ~~28~~ 34 bytes
```
a=>a.filter(o=x=>(o[x]=-~o[x])==2)
```
[Try It Online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@z/R1i5RLy0zpyS1SCPftsLWTiM/uiLWVrcORGna2hpp/k/OzyvOz0nVy8lP10jTiI7V1FTQ11eIjuVCk9A11DHQMcQpbYiQM8SQNAZqBWrWARlhqmMMU2gMNhHDImMTsGIQbaJjoWMCUw4WwFBuoAOHMIUGsf8B)
[Answer]
# Common Lisp, 57 bytes
```
(remove-duplicates(remove-if(lambda(x)(<(count x d)2))d))
```
]