# Count repetitions of an array

You will receive an array and must return the number of integers that occur more than once.

[234, 2, 12, 234, 5, 10, 1000, 2, 99, 234]


This will return 2, since each of 234 and 2 appear more than once.

[234, 2, 12, 234]
[2, 12, 234, 5, 10, 1000, 2]


The list will never be more than 100k integers long, and the integers inside the list will always be in between -100k and 100k.

Integers should be counted if they occur more than once, so if an integer occurs 3 times then it will still only count as one repeated integer.

Test cases

[1, 10, 16, 4, 8, 10, 9, 19, 2, 15, 18, 19, 10, 9, 17, 15, 19, 5, 13, 20]  = 4
[11, 8, 6, 15, 9, 19, 2, 2, 4, 19, 14, 19, 13, 12, 16, 13, 0, 5, 0, 8]     = 5
[9, 7, 8, 16, 3, 9, 20, 19, 15, 6, 8, 4, 18, 14, 19, 12, 12, 16, 11, 19]   = 5
[10, 17, 17, 7, 2, 18, 7, 13, 3, 10, 1, 5, 15, 4, 6, 0, 19, 4, 17, 0]      = 5
[12, 7, 17, 13, 5, 3, 4, 15, 20, 15, 5, 18, 18, 18, 4, 8, 15, 13, 11, 13]  = 5
[0, 3, 6, 1, 5, 2, 16, 1, 6, 3, 12, 1, 16, 5, 4, 5, 6, 17, 4, 8]           = 6
[11, 19, 2, 3, 11, 15, 19, 8, 2, 12, 12, 20, 13, 18, 1, 11, 19, 7, 11, 2]  = 4
[6, 4, 11, 14, 17, 3, 17, 11, 2, 16, 14, 1, 2, 1, 15, 15, 12, 10, 11, 13]  = 6
[0, 19, 2, 0, 10, 10, 16, 9, 19, 9, 15, 0, 10, 18, 0, 17, 18, 18, 0, 9]    = 5
[1, 19, 17, 17, 0, 2, 14, 10, 10, 12, 5, 14, 16, 7, 15, 15, 18, 11, 17, 7] = 5

• What do you mean by Once it counts the repetition, don't count again? Also, since we want to find the repetition of a specific integer, how would we know which integer to search for if we are not given it? Lastly, the test cases are a bit confusing; which are output and which are input? Feb 24, 2019 at 18:19
• I've edited this to try to make it a bit clearer. Is this what you intended? Also, please put answers in for those test cases. Feb 24, 2019 at 18:21
• I have added some answers to the test cases, sorry if I go them wrong Feb 24, 2019 at 19:20
• I've voted to close this question until you confirm this is what you intended. Feb 24, 2019 at 21:01
• Related (output the non-unique items, instead of the amount of non-unique items). Feb 24, 2019 at 21:38

# Japt -x, 5 bytes

ü ®¦q


Run it online

# JavaScript (Node.js), 93 bytes

a=>Object.values(a.reduce((a,c)=>Object.assign(a,{[c]:(a[c]|0)+1}),{})).filter(i=>i>1).length


Try it online!

# Pyth, 10 bytes

lf<1/QT.{Q


Probably a way to golf it, I'm quite rusty with pyth...

Alternate 10 byte version...

lf>lT1.gSk


Try it online!

# PowerShell, 33 bytes

($args|group|?{$_.Count-1}).Count


Try it online!

# Pyth, 8 bytes

lfthTr8S


Try it online here, or verify all the test cases at once here.

## PHP (112 Bytes)

<?php $c=0;foreach(array_count_values(json_decode(file_get_contents('php://stdin'))) as$b)if($b>1)$c++;echo $c;  The assignment does not make it clear if the input is received via Stdin in exactly given format or as separate parameters in Argv, so here is a variant for argv, 91 Bytes: <?php array_shift($argv);$c=0;foreach(array_count_values($argv) as $b)if($b>1)$c++;echo$c;

• Yes, you can take input via the command line arguments (as per standard IO formats). Though wouldn't there be problems if the filename was numerical?
– Jo King
Feb 25, 2019 at 10:27
• @JoKing Sure, I fixed it. Feb 25, 2019 at 10:33

# Factor, 42 bytes

: d ( x -- ) duplicates members length . ;


Try it online!

# Perl 5-ap, 35 bytes

map$k{$_}++,@F;$_=grep$_>1,values%k


Try it online!

# JavaScript (Node.js), 67 bytes

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


Try it online!

# Stax, 5 bytes

ëB♀╡╙


Run and debug it

# Husk, 5 bytes

LuṠ-u


Try it online!

L        The number of
u       unique elements of
Ṡ-u    the input with every unique element removed once.


# APL(NARS), 9 chars, 18 bytes

{≢∪⍵∼⍦∪⍵}


test:

  f←{≢∪⍵∼⍦∪⍵}
f 1 2 2 3 1 1 1 1 1 1
2
f 234, 2, 12, 234, 5, 10, 1000, 2, 99, 234
2
f 1, 10, 16, 4, 8, 10, 9, 19, 2, 15, 18, 19, 10, 9, 17, 15, 19, 5, 13, 20
4
f 11, 8, 6, 15, 9, 19, 2, 2, 4, 19, 14, 19, 13, 12, 16, 13, 0, 5, 0, 8
5


# C (gcc), 71 bytes

f(r,l,t)int*r;{int n[7<<15]={};for(t=0;l;t+=!~n[r[--l]+100000]--);r=t;}


Try it online!

Naive approach. 7<<15=229376.

• 70 bytes Mar 29, 2019 at 18:24

# Gaia, 6 bytes

e:uDul


Try it online!

e	| eval as a list
:	| duplicate
u	| uniquify
D	| multiset difference; keep only repeated elements
u	| uniquify
l	| find length

# Python 3, 93 bytes

import collections as c;print(sum(filter(lambda x:x>1,[y-1 for y in c.Counter(i).values()])))


Try it online!

• This is a snippet; you'd need to take input to make a full program or function (you cannot assume it's already in a variable). Feb 24, 2019 at 21:54
• @JonathanAllan I'm also having a hard time figuring out how to answer these questions. In the StackExchange CodeGolf tour, there's no info about this. Also, is tio.run website part of this community..? In addition, is this the correct format
– DxTx
Feb 25, 2019 at 7:07
• @DT this or this would be OK; although the code does not perform the task correctly. Feb 25, 2019 at 7:35
• @DT TIO is not part of StackExchange but it was developed and is maintained by one of the PPCG moderators, Dennis. Feb 25, 2019 at 7:37
• @JonathanAllan, Got it. Thank you.
– DxTx
Feb 25, 2019 at 8:19