g | x | w | all
Bytes Lang Time Link
008APLNARS250913T033712ZRosario
007Japt230106T121452ZShaggy
005Uiua250911T213942Znyxbird
042AWK250911T165425Zxrs
091Elm230107T051120ZWheat Wi
058Curry PAKCS230107T134756ZWheat Wi
034JavaScript170508T164931ZShaggy
015Zsh coreutils230106T070749Zroblogic
022jq230106T044311Zpmf
036JavaScript Node.js230106T044256Zl4m2
010Haskell + hgl230104T053633ZWheat Wi
nan230104T145116ZThe Thon
00405AB1E180607T075600ZKevin Cr
040Arturo230104T141428Zchunes
011Pip p230104T054828ZDLosc
010Factor221017T134040Zchunes
004Vyxal221017T132306Zpacman25
024R201207T233955ZDominic
004Husk201207T225447ZDominic
018Perl 5201207T185428ZXcali
028Ruby151013T131335ZCristian
009Burlesque200226T190410ZDeathInc
043JavaScript Node.js190226T152005ZKamil Na
060JavaScript Node.js190226T150329ZKamil Na
009APL Dyalog Unicode151013T134034ZAdá
014Perl 6181023T234735ZJo King
041Kotlin181023T223155Zsnail_
007K oK180828T210630Zmkst
036Python 2.7180606T171506ZKhalil
075PHP180606T144149ZLuis fel
007Japt180606T143635ZOliver
035PHP151015T083011Zinsertus
004Jelly170508T155701Zuser6213
030Python 3151013T125321ZThe Fift
016Perl 6151027T223225ZBrad Gil
010K not K5151015T204932Zkirbyfan
013J151014T090232Zmarinus
023Mathematica151015T073042ZLLlAMnYP
042SQL151013T182823ZMickyT
040C#151014T143916ZCooler R
080Java 8151014T130406ZRnet
024R151013T135958ZMutador
029PowerShell151013T134530ZAdmBorkB
022Octave151014T092718Zalephalp
042Python 2.7151013T111959Zdieter
018STATA151014T043133Zbmarks
054LINQ151014T010449Znoisyass
007Pyth151013T232829Zizzyg
033Octave151013T224856Zbeaker
143Python151013T224547ZIoannes
030Python 3.5151013T210723Zxnor
029Julia151013T175408ZGlen O
040Matlab / Octave151013T104706ZLuis Men
012Shell + GNU coreutils151013T161536ZDigital
007Pyth151013T150717ZDennis
005K5151013T150058ZJohnE
010CJam151013T102301Zaditsu q
104Hassium151013T140824ZJacob Mi
037JavaScript ES6151013T134720ZCristian
057Common Lisp151013T131145Znanny
032Haskell151013T105728ZC. Quill
029Mathematica151013T105930Zalephalp
026Mathematica151013T112406ZMartin E

APL(NARS), 8 chars

{∪⍵∼⍦∪⍵}

For this there is only to know how work the function ∼⍦.

For 2 sets ∼ make the usual A-B of set example

  1 2 3 4 4 4 ∼ 1 4
2 3 

instead A∼⍦B cut one element of A if it present in B and only that element

  1 2 3 4 4 4 ∼⍦ 1 4
2 3 4 4 

∪ unique instead return its input without element repetitions

  ∪1 2 3 4 4 4
1 2 3 4 

so for explain better

∪⍵∼⍦∪⍵
     ∪⍵ unique ⍵ input 
 ⍵∼⍦    make the difference as above, so it return only multiple elements of ⍵
∪       make list unique

one alternative is using partitions (20 chars)

  {∪∊m/⍨2≤≢¨m←⊂⍨⍵[⍋⍵]} 1 4 5 1 1 4 8 3 3 8
┌4───────┐
│ 1 3 4 8│
└~───────┘

one alternative is use count elements (19 chars)

  {∪⍵/⍨2≤{+/⍵=w}¨w←⍵} 1 4 5 1 1 4 8 3 3 8
┌4───────┐
│ 1 4 8 3│
└~───────┘

test:

  f←{∪⍵∼⍦∪⍵}
  f ⍬

  f ¯1,0,1

  f 1,1
1 
  f 3 0 0 1 1 0 5 3
0 1 3 
  f ¯34 0 1 ¯34 4 8 4
¯34 4 

Japt, 7 bytes

ü lÉ cÎ

Try it (includes all test cases)

ü lÉ cÎ     :Implicit input of array
ü           :Group & sort by value
  l         :Filter by length
   É        :  Minus 1
     c      :Flat map
      Î     :  First element

5 bytes

If including empty elements in the output is permitted.

ü ÕÅÎ

Try it

ü ÕÅÎ     :Implicit input of array
ü         :Group & sort by value
  Õ       :Transpose
   Å      :Slice off first element
    Î     :Get first element

Uiua, 5 bytes

▽=1⊸⧆

Try it!

▽ keep ⊸ by the indices whose number of previous ⧆ occurences = equals 1

AWK, 42 bytes

{++b[$1]}END{for(j in b)if(b[j]>1)print j}

Attempt This Online!

Elm, 91 bytes

e=List.member
g x z=case z of
 a::b->g(a::x)b++if e a b&&not(e a x)then[a]else[]
 _->[]
g[]

Curry (PAKCS), 58 bytes

x!(y:z)|elem y z&&all(/=y)x=y:(y:x)!z|1>0=x!z
_![]=[]
([]!)

Attempt This Online!

Weirdish port of my Elm answer. Curry has nicer built in functions and pattern matching than Elm.

JavaScript, 35 28 34 bytes

a=>a.filter(o=x=>(o[x]=-~o[x])==2)

Try It Online!

Zsh coreutils, 15 bytes

sort|uniq -d|rs

Try it online!

jq, 22 bytes

[group_by(.)[][1:2][]]

Try it online!

Explanation:

[                    ]     # collect
                   []      # each
              [1:2]        # second item
            []             # from each
 group_by( )               # array of arrays of
          .                # identical values

JavaScript (Node.js), 36 bytes

a=>a.filter(o=x=>a.a+a+a==(o[x]+=a))

Try it online!

Haskell + hgl, 11 10 bytes

(!!1)~<<bg

Attempt This Online!

Explanation

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.

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

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

05AB1E, 8 6 5 4 bytes

¢ÏKÙ

Try it online or verify all test cases.

Explanation:

      #  e.g. input=[1,2,3,2,1,1,6,4,5,6]
¢     # Count how many times each item of the (implicit) input-list occurs in the
      # (implicit) input-list
      #  → [3,2,1,2,3,3,2,1,1,2]
 Ï    # Only keep the values in the (implicit) input-list at the truthy (==1) indices
      #  → [3,4,5]
  K   # Remove those values from the (implicit) input-list, leaving all non-unique items
      #  → [1,2,2,1,1,6,6]
   Ù  # Uniquify that list of non-unique items
      #  → [1,2,6]
      # (after which the result is output implicitly)

Arturo, 40 bytes

unique select b'x[1<size select b=>[=x]]

Try it

Pip -p, 11 bytes

UQ:_Ng>1FIg

Takes the integers as command-line arguments. Attempt This Online!

Explanation

UQ:_Ng>1FIg
          g  List of command-line arguments
        FI   Filter by this function:
   _N          The number of times this element appears in
     g         the list of command-line arguments
      >1       is greater than one
UQ:          Uniquify the resulting list

Factor, 10 bytes

duplicates

Try it online!

Builtin

Vyxal, 4 bytes

UÞ⊍U

Try it Online!

Multiset Symmetric difference is very powerful

R, 24 bytes

names((t=table(v))[t>1])

Try it online!

Completely different approach to the previous R answer for the same number of bytes when written (as here) as a snippet with pre-defined variable v, but 4 bytes shorter as a full program (which, admittedly, isn't required by the challenge).
Outputs the non-unique elements as a vector of strings.


R, 25 bytes

(r=rle(sort(v)))$v[r$l>1]

Try it online!

One byte longer (and yet another approach) if you want to output as an integer vector.

Husk, 4 bytes

u-u¹

Try it online!

u       # unique element of
 -      # set difference between
  u¹    # unique elements of input  
        # and input

Perl 5, 18 bytes

Since a snippet is allowed here, the input is assumed to be in @F. The TIO link adds a little I/O around it.

grep++$k{$_}==2,@F

Try it online!

Ruby, 30 28 bytes

In the Interactive Ruby Shell:

d.select{|x|d.count(x)>1}|[]

Saved 2 bytes thanks to Kirill L.

Burlesque, 9 bytes

peJNB\\NB

Try it online!

pe # Parse and push
J  # Duplicate
NB # Remove duplicate elements
\\ # Difference between nubbed and original lists
NB # Nub the difference

JavaScript (Node.js), 43 bytes (another try)

a=>a.filter((t={},e=>!(1-(t[e]=++t[e]|0))))

Try it online!

JavaScript (Node.js), 60 bytes

f=>[...new Set(f.filter(e=>f.indexOf(e)!=f.lastIndexOf(e)))]

Try it online!

APL (Dyalog Unicode), 13 9 bytesSBCS

Anonymous tacit prefix function.

∊(⊂1↓⊣¨)⌸

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)

Perl 6, 14 bytes

*.repeated.Set

Try it online!

Gets a Set of the repeated elements.

Kotlin, 41 bytes

{it.filter{v->it.count{it==v}>1}.toSet()}

Try it online!

K (oK), 7 bytes

Solution:

&1<#:'=

Try it online!

Explanation:

&1<#:'= / the solution
      = / group, key => value (index)
   #:'  / count length of each group
 1<     / 1 less than 
&       / keys where true

Python 2.7, 36 bytes

list({x for x in i if i.count(x)>1})

Where i is the input

PHP, 75 bytes

function a($b){return array_unique(array_diff_assoc($b,array_unique($b)));}

Try it online!

Japt, 7 bytes

â £kX â

Try it online!

Explanation:

â £kX â
â         // Get all unique items from the input
  £       // Map X through the results
   kX     //   Remove X from the input
      â   //   Get unique items
-h        // Return the last item

PHP, 35 37 bytes

Pretty straight forward:

array_diff_key($a,array_unique($a))

As a note: I didn't add the ; at the end of the line, as the questions states:

Your answer may be a snippet which assumes the input to be stored in a variable (d, say) and evaluates to the correct result

So this snippet could be used like this and evaluates to the correct result:

print implode(' ', array_diff_key($a,array_unique($a)));

Another note

The code above works for all test cases provided in the challenge. In those all non-unique characters are at most duplicates. If a element can occur more than two times, another array_unique() would be necessary, which increases the length to 49 bytes:

array_unique(array_diff_key($a,array_unique($a)))

Edits

Jelly, 4 bytes, language postdates challenge

œ-QQ

Try it online!

Same algorithm as the accepted answer, just a shorter syntax.

Python 3 - 33 30 bytes

{_ for _ in d if d.count(_)>1}

Repl output, d as input.

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)

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!

J, 12 14 13 bytes

~.d#~1<+/=/~d

Assumes the list is in d.

Explanation:

         =/~d   NB. compare each element in d to each element in d
       +/       NB. sum the columns (giving amount of occurrences)
     1<         NB. see which columns are greater than 1 (=not unique)
  d#~           NB. select those elements from d 
~.              NB. unique elements from that

If an anonymous function is OK as well, it can be shortened to 13 12:

~.#~1<+/"1@=

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.

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.

C# - 40

i.GroupBy(g=>g).SelectMany(s=>s.Skip(1))

Using select many to be able to use Skip and skip the first occurrence if it exists.

Java 8, 80 Bytes

x.stream().filter(i->x.indexOf(i)!=x.lastIndexOf(i)).collect(Collectors.toSet())

Assuming x contains the input List of numbers.

R, 31 24 bytes

Thanks to 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.

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ć

Octave, 22 bytes

Based on Luis Mendo's answer.

d(sum(triu(d==d'))==2)

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

STATA, 18 bytes

bys v:drop if _n-2

Note that this requires the paid version of STATA.

Assumes the data is stored in a variable v and then the result will be in v at the end. It works by sorting by v and grouping duplicate values together. Each duplicate value will have at least two values, which means it can drop anything that is not the second element of each value. Third and subsequent elements will already be represented and the first element will either be unique or represented by the second.

For example, make a file a.b with data:

3
0
0
1
1
0
5
3

Then run the following code

insheet using a.b,clear
rename v1 v
bys v:drop if _n-2 //the actual code that does stuff
list v,noobs noheader

LINQ,62 54 bytes

Kinda new here, but here goes nothing.

d.GroupBy(c=>c).Where(g=>g.Count()>1).Select(g=>g.Key)

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.

Octave, 33 bytes

[~,a]=unique(d);d(a)=[];unique(d)

Here it is on ideone. I've wrapped the snippet in a function so I could call it using all of the sample inputs.

Python, 143 bytes

There are already some very good Python answers out there (see @dieters, @ppperry & @xnor answers) so I decided to take a different approach, have some fun with recursion and python lambda functions and see what could I come up with. This is not even close to the best answers here but it was fun to think.

The program takes the integer list as a parameter of function p and returns a list containing non-unique elements.

p=lambda i:[j for j in(lambda n:[]if len(n)<=1 else[(lambda x:x[0]if len([1 for o in x[1:]if x[0]==o])==1 else 'N')(n)]+p(n[1:]))(i) if j!='N']

Two line version for better readability:

p=lambda i:[j for j in(lambda n:[]if len(n)<=1 else[(lambda x:x[0]if 
len([1 for o in x[1:]if x[0]==o])==1 else 'N')(n)]+p(n[1:]))(i) if j!='N']

Short Explanation

The inner lambda takes a list x as a parameter and returns the first element of such list if it is repeated only once in the rest of the list (x[1:]). If not it returns 'N'.

The lambda in between the outer and inner lambdas is the one in charge of the recursive search. This returns a list containing the non-unique elements and plenty of 'N's. This is the one which takes the integer list as a parameter.

The outer lambda filters the resulting list getting rid of the unwanted 'N's.

Test cases

p([])
[]
p([-1,0,1])
[]
p([3, 0, 0, 1, 1, 0, 5, 3])
[3,0,1]

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)}

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. summing 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.

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 in Octave.

Shell + GNU coreutils, 12

sort|uniq -d

Test output:

$ printf "%s\n" -34 0 1 -34 4 8 4 | ./nonuniq.sh 
-34
4
$ 

Pyth, 7 bytes

S{.-Q{Q

Try it online.

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.

K5, 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)

CJam, 10

Assuming the array is already in variable D (based on this comment):

D{De=(},_&

Try it online

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

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

Hassium, 104 Bytes

func main(){r=[];i=[];foreach(e in d)if(!i.contains(e))i.add(e)else if(!r.contains(e))r.add(e);print(r)}

Run online and see expanded here

JavaScript (ES6), 37 bytes

Run this in the JavaScript console:

e={};d.filter(x=>(e[x]=1+e[x]||0)==1)

Common Lisp, 57 bytes

(remove-duplicates(remove-if(lambda(x)(<(count x d)2))d))

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.

Mathematica, 31 29

Cases[{s_,t_/;t>1}:>s]@*Tally

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.