| Bytes | Lang | Time | Link |
|---|---|---|---|
| 028 | Juby | 250503T020951Z | Jordan |
| 004 | Vyxal | 231016T013629Z | lyxal |
| 007 | Uiua | 231013T232944Z | chunes |
| 005 | Thunno 2 L | 230714T085713Z | The Thon |
| 007 | Pyt | 230211T173012Z | Kip the |
| 031 | Arturo | 230210T034652Z | chunes |
| 005 | Vyxal | 221020T170811Z | pacman25 |
| 006 | Gaia | 190330T165658Z | Giuseppe |
| 008 | APL Dyalog Unicode | 190224T183352Z | Adá |
| 071 | C gcc | 190322T214628Z | att |
| 018 | APLNARS | 190322T055413Z | user5898 |
| 005 | Husk | 190322T021430Z | Unrelate |
| 005 | Japt x | 190227T225246Z | Oliver |
| 039 | PHP | 190226T101141Z | Titus |
| 007 | Brachylog | 190226T084136Z | Unrelate |
| 041 | Haskell | 190226T071925Z | proud ha |
| 005 | Stax | 190226T015532Z | recursiv |
| 041 | Haskell | 190226T013825Z | xnor |
| 067 | JavaScript Node.js | 190225T235043Z | Kamil Na |
| 035 | Perl 5 ap | 190225T230420Z | Xcali |
| 008 | k | 190225T215114Z | J. Sendr |
| 006 | Pyth | 190225T191727Z | user4854 |
| 042 | Factor | 190225T191710Z | Galen Iv |
| 040 | C# Visual C# Interactive Compiler | 190224T190305Z | Gymhgy |
| 007 | APL Dyalog Extended | 190225T072056Z | Adá |
| 006 | Japt | 190224T230010Z | Quintec |
| 112 | PHP 112 Bytes | 190225T100413Z | rexkogit |
| 008 | Pyth | 190225T101758Z | Sok |
| 005 | MATL | 190225T093942Z | Luis Men |
| 033 | PowerShell | 190225T091454Z | mazzy |
| 073 | Java 8 | 190224T213744Z | Kevin Cr |
| 009 | J | 190224T193022Z | Galen Iv |
| 063 | Python 3 | 190225T060557Z | pizzapan |
| 010 | Pyth | 190225T045516Z | JPeroute |
| 126 | Rust | 190225T050207Z | don brig |
| 095 | C clang | 190225T000927Z | Collin P |
| 034 | Wolfram Language | 190224T233921Z | DavidC |
| 054 | Clean | 190224T221549Z | Οurous |
| 019 | Retina 0.8.2 | 190224T223515Z | Neil |
| 042 | Haskell | 190224T221637Z | Laikoni |
| 093 | JavaScript Node.js | 190224T221517Z | Kamil Na |
| 015 | Perl 6 | 190224T215842Z | Jo King |
| 040 | Element | 190224T220010Z | PhiNotPi |
| 004 | Jelly | 190224T213742Z | Jonathan |
| 038 | Python 3 | 190224T200758Z | Kirill L |
| 004 | 05AB1E | 190224T194316Z | Emigna |
| 034 | Ruby | 190224T194817Z | Kirill L |
| 040 | JavaScript ES6 | 190224T193841Z | Arnauld |
| 047 | Haskell | 190224T192855Z | Wheat Wi |
| 018 | Bash + coreutils | 190224T191913Z | Digital |
| 020 | R | 190224T183402Z | MickyT |
Vyxal, 4 bytes
Ċċ∑t
Just another 4 byter
Explained
Ċċ∑t
Ċ # [[item, count(item)] for item in input]
ċ # Each item != 1?
∑ # Summate. Because this is implemented as reduce by addition, it vectorises element-wise when folding.
t # Get the last item of that (the number of counts that != 1)
💎
Created with the help of Luminespire.
Uiua, 7 bytes
/+>1⍘⊚⊛
/+>1⍘⊚⊛
⊛ # classify (i.e. map integers -> naturals)
⍘⊚ # inverse where (occurrences)
>1 # where are they greater than one?
/+ # sum
Thunno 2 L, 5 bytes
Uæc1Q
Explanation
Uæc1Q # Implicit input
U # Uniquify the input
æ # Filter it by:
c # Count in the input
1Q # Is not equal to 1
# Push the length
# Implicit output
Pyt, 7 bytes
ĐỤ⇹ɔ⁻žŁ
Đ implicit input; Đuplicate on the stack
Ụ get Ụnique elements
⇹ɔ ɔount occurrences of each in original list
⁻žŁ decrement; remove žeros; get Łength; implicit print
Arturo, 49 31 bytes
$=>[tally&|enumerate[k,v]->v>1]
-18 bytes due to Arturo 0.9.83 providing tally and enumerate.
$ => [ ; a function
tally & ; create a dictionary of elements and their occurrences from the input
| ; then...
enumerate[k,v]-> ; count the number of key-value pairs where...
v>1 ; the value (occurrences) is greater than one
] ; end function
Vyxal, 5 bytes
UÞ⊍UL
Typical symmetric difference with the unique values in the list, take the length of the unique values in that list.
Gaia, 6 bytes
e:uDul
e | eval as a list
: | duplicate
u | uniquify
D | multiset difference; keep only repeated elements
u | uniquify
l | find length
APL (Dyalog Unicode), 9 8 bytesSBCS
-1 thanks to ngn
Anonymous tacit prefix function.
+/1<⊢∘≢⌸
+/ sum of
1< whether 1 is less than
…⌸ for each unique element:
⊢∘ ignoring the actual unique element,
≢ the count of its occurrences
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;}
Naive approach. 7<<15=229376.
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
Husk, 5 bytes
LuṠ-u
L The number of
u unique elements of
Ṡ-u the input with every unique element removed once.
PHP, 39 bytes
a nice occasion to use variable variables:
foreach($argv as$v)$r+=++$$v==2;echo$r;
takes input from command line arguments. Run with -nr or try it online.
$argv[0] is - and that appears only once in the arguments, so it does not affect the result.
Brachylog, 7 bytes
ọzt;1xl
Explanation:
ọ For every unique element E of the input, [E, how many times E occurs]
zt The last elements of the previous value.
;1x With every 1 removed,
l how many there are.
Haskell, 41 bytes
f[]=0
f(a:s)=sum[1|filter(==a)s==[a]]+f s
This solution basically counts how many elements of the list have the same element appear exactly once later in the list.
Haskell, 41 bytes
f(h:t)=sum[1|filter(==h)t==[h]]+f t
f _=0
Count suffixes where the first element h appears exactly once in the part t that comes after.
Haskell, 40 bytes
import Data.List
f l=length$nub$l\\nub l
Stealing the method from other answers.
JavaScript (Node.js), 67 bytes
a=>[...new Set(a.filter(e=>a.indexOf(e)!=a.lastIndexOf(e)))].length
k, 8 bytes
+/1<#:'=
reads as: sum (length each group) > 1
+/ is sum (plus over)
#:' is length each
= is group (ex. =1 2 1 6 7 2 generates 1 2 6 7!(0 2;1 5;,3;,4) (dictionary of unique value and its positions)
Use example (first test case)
+/1<#:'=1 10 16 4 8 10 9 19 2 15 18 19 10 9 17 15 19 5 13 20
writes 4
Pyth, 6 bytes
l{.-Q{
Explanation
l{.-Q{
{Q Deduplicate the (implicit) input.
.-Q Remove the first instance of each from the input.
l{ Count unique.
C# (Visual C# Interactive Compiler), 40 bytes
n=>n.GroupBy(c=>c).Count(c=>c.Count()>1)
The first draft of the spec was unclear, and I thought it mean return all the elements that appear more than once. This is the updated version.
Somehow I didn't notice that my code returned the number of elements that appeared once. Thanks to Paul Karam for catching that!
APL (Dyalog Extended), 8 7 bytesSBCS
Anonymous tacit prefix function using Jonah's method.
+/1<∪⍧⊢
+/ the total number occurrences
literally the sum of Truths
1< where one is less than
∪ the unique elements'
⍧ count in
⊢ the unmodified argument
Japt, 12 11 9 8 6 bytes
ü èÈÊÉ
With lots of help from @ASCII-Only, and suggestions from @Shaggy and @Luis felipe De jesus Munoz.
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;
MATL, 5 bytes
8#uqz
Try it online! Or verify all test cases.
Explanation
8#u % Number of ocurrences of each unique value
q % Subtract 1
z % Number of nonzeros
Java 8, 74 73 bytes
L->L.stream().filter(i->L.indexOf(i)<L.lastIndexOf(i)).distinct().count()
Explanation:
L-> // Method with ArrayList parameter and integer return-type
L.stream() // Create a stream of the input-list
.filter(i-> // Filter it by:
L.indexOf(i) // Where the first index of a value
<L.lastIndexOf(i)) // is smaller than the last index of a value
.distinct() // Deduplicate this filtered list
.count() // And return the count of the remaining values
J, 11 9 bytes
-2 bytes thanks to Jonah!
1#.1<1#.=
Original solution:
1#.(1<#)/.~
Explanation:
/.~ group the list by itself
( ) for each group
1<# is the length greater than 1
1#. sum by base-1 conversion
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
Rust, 126 bytes
let f=|v:Vec<i32>|{let mut u=v.clone();u.sort();u.dedup();u.iter().filter(|i|v.iter().filter(|n|**n==**i).count()>1).count()};
I give up. This is basically the same as Ruby. There is "another way" creating an array and indexing into it using the values in the input vector, +100000, however the type conversions (as usize / as i32) take up too much space.
C (clang) 175 117 95 bytes
c(*a,*b){return*a-*b;}r(*l,m){qsort(l,m,4,c);return((!m||l[1]-*l)&l[-1]==*l)+(m?r(l+1,m-1):0);}
This is the first time I've submitted one of these, so let me know if there are any issues with formatting or anything.
Updates from the comments:
- -58 to 117 bytes from Jo King
- -80 to 95 bytes from ASCII-only
Wolfram Language 34 bytes
Length@DeleteCases[Gather@#,{x_}]&
Gather groups identical integers into lists.
DeleteCases[...{x_}] eliminates lists containing a single number.
Length returns the number of remaining lists (each containing two or more identical integers.
Clean, 59 54 bytes
import StdEnv,StdLib
$l=sum[1\\[_,_:_]<-group(sort l)]
Sorts the list, groups adjacent equal elements, and counts the number with more than 1 item.
Retina 0.8.2, 19 bytes
O`.+
m`^(.+)(¶\1)+$
Try it online! Link includes test suite which splits each line on commas. Explanation:
O`.+
Sort equal values together.
m`^(.+)(¶\1)+$
Count the number of runs of at least two values.
Haskell, 42 bytes
f s=sum[1|x<-[-9^6..9^6],filter(==x)s>[x]]
Try it online! Abuses the fact the the integers in the list are guaranteed to be within -100k and 100k.
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
Perl 6, 15 bytes
+*.repeated.Set
Pretty self explanatory. An anonymous code block that gets the count (+) of the Set of elements among the repeated elements of the input (*).
I've realised I've posted almost the exact same solution for a related question.
Element, 40 bytes
_(#'{"2:0+4:'~1+";~2=[''1+""]$2+'[(#]'}`
This requires input to be in a precise format like [234, 2, 1000, 2, 99, 234] (enclosed with [] with a comma and space between integers).
Explanation:
_ input
(# delete the [ at start of input
'{" '} WHILE the string is non-empty
'{"2: '} duplicate it
'{" 0+ '} add 0 to coerce to integer (gets next number in array)
'{" 4: '} make 3 additional copies
'{" ' '} temporarily move 1 copy to control stack
'{" ~ '} fetch the current map value for given integer
'{" 1+ '} increment map value
'{" " '} retrieve temporary copy of integer (the key for the map)
'{" ; '} store updated map value
'{" ~ '} fetch map value again (1 if 1st instance, 2 if 2nd, etc.)
'{" 2= '} test for map value = 2, this is the first duplication
'{" [ ] '} IF
'{" ['' ] '} move stuff from main stack to control stack
'{" [ 1+ ] '} increment the counter of duplicate (bottom of stack)
'{" [ ""] '} move stuff back to main stack
'{" $ '} take length of current integer
'{" 2+ '} add 2 (for the comma and space)
'{" '[ ]'} FOR loop with that number
'{" '[(#]'} trim those many characters from front of input string
` output result
Jelly, 4 bytes
ĠITL
...Or ĠIƇL
How?
ĠITL - Link: list of integers e.g. [234, 2, 12, 234, 5, 10, 1000, 2, 99, 234]
Ġ - group indices by value [[2,8],5,6,3,9,[1,4,10],7]
I - incremental differences [[6],[],[],[],[],[3,6],[]]
T - truthy indices [1,6]
L - length 2
IƇ would filter to keep only truthy results of I ([[6],[3,6]]) which also has the desired length.
05AB1E, 4 bytes
Ù¢≠O
Try it online! or as a Test Suite
Explanation
O # sum
≠ # the false values
¢ # in the count
Ù # of each unique digit in input
Haskell, 47 bytes
f[]=0
f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b
This is the naïve approach. There is likely something that could be done to improve this.
f[]=0
We return 0 for the empty list
f(a:b)
In the case of a non-empty list starting with a and then b.
|x<-filter(/=a)b,x/=b=1+f x
If filtering a out of b is different from b (that is a is in b) then we return 1 more than f applied to b with the as filtered out.
|1>0=f b
If filtering as doesn't change b then we just run f across the rest.
Here is another similar approach that has the same length:
f[]=0
f(a:b)|elem a b=1+f(filter(/=a)b)|1>0=f b
R, 20 bytes
Is this what you are after? Uses table to count the occurrences of each of the scan input values. Tests if count is > 1 and sums the trues.
sum(table(scan())>1)