Count repetitions of an arrayShortest Unique SubstringsWrite a program that finds the most occurring paired...

Why don't you get burned by the wood benches in a sauna?

Why is it that Bernie Sanders is always called a "socialist"?

How do I fight with Heavy Armor as a Wizard with Tenser's Transformation?

Critique vs nitpicking

Do we still track damage on indestructible creatures?

GPSD issues on 16.4

Smooth projection of a surf plot - tikz/gnuplot

What happened to Hermione’s clothing and other possessions after the memory wipe in Deathly Hallows?

How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?

Can I travel from country A to country B to country C without going back to country A?

What does an unprocessed RAW file look like?

How can find the 2D Voronoi cell area distribution?

What species should be used for storage of human minds?

Other than edits for international editions, did Harry Potter and the Philosopher's Stone receive errata?

Is there a way to pause a running process on Linux systems and resume later?

Was Opportunity's last message to Earth "My battery is low and it's getting dark"?

Does Plato's "Ring of Gyges" have a corrupting influence on its wearer?

Why does a single AND gate need 60 transistors?

Is practicing on a digital piano harmful to an experienced piano player?

How to deal with an underperforming subordinate?

Given a total recursive function, can you always compute its fixed-point?

How can I give a Ranger advantage on a check due to Favored Enemy without spoiling the story for the player?

Players preemptively rolling, even though their rolls are useless or are checking the wrong skills

Sticky Strike or Sticky Delta



Count repetitions of an array


Shortest Unique SubstringsWrite a program that finds the most occurring paired letter in a stringLisp Extraction MissionOrdering words to fit in a given stringReverse Deltas of an ArraySort and Re-apply Deltas of an ArrayTurn an integer n into a list containing it n timesRebuild a rectangular array from a cornerMost Common MultipleLongest Repeating Subsequence of a Single Digit













3












$begingroup$


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 both 234 and 2 are repeated twice.



[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









share|improve this question









New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    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?
    $endgroup$
    – Embodiment of Ignorance
    1 hour ago








  • 2




    $begingroup$
    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.
    $endgroup$
    – Riker
    1 hour ago










  • $begingroup$
    You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
    $endgroup$
    – Adám
    1 hour ago










  • $begingroup$
    I have added some answers to the test cases, sorry if I go them wrong
    $endgroup$
    – MickyT
    27 mins ago
















3












$begingroup$


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 both 234 and 2 are repeated twice.



[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









share|improve this question









New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$












  • $begingroup$
    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?
    $endgroup$
    – Embodiment of Ignorance
    1 hour ago








  • 2




    $begingroup$
    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.
    $endgroup$
    – Riker
    1 hour ago










  • $begingroup$
    You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
    $endgroup$
    – Adám
    1 hour ago










  • $begingroup$
    I have added some answers to the test cases, sorry if I go them wrong
    $endgroup$
    – MickyT
    27 mins ago














3












3








3





$begingroup$


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 both 234 and 2 are repeated twice.



[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









share|improve this question









New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




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 both 234 and 2 are repeated twice.



[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






code-golf array-manipulation






share|improve this question









New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 40 mins ago









MickyT

10k21535




10k21535






New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









jayko03jayko03

1163




1163




New contributor




jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






jayko03 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • $begingroup$
    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?
    $endgroup$
    – Embodiment of Ignorance
    1 hour ago








  • 2




    $begingroup$
    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.
    $endgroup$
    – Riker
    1 hour ago










  • $begingroup$
    You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
    $endgroup$
    – Adám
    1 hour ago










  • $begingroup$
    I have added some answers to the test cases, sorry if I go them wrong
    $endgroup$
    – MickyT
    27 mins ago


















  • $begingroup$
    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?
    $endgroup$
    – Embodiment of Ignorance
    1 hour ago








  • 2




    $begingroup$
    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.
    $endgroup$
    – Riker
    1 hour ago










  • $begingroup$
    You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
    $endgroup$
    – Adám
    1 hour ago










  • $begingroup$
    I have added some answers to the test cases, sorry if I go them wrong
    $endgroup$
    – MickyT
    27 mins ago
















$begingroup$
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?
$endgroup$
– Embodiment of Ignorance
1 hour ago






$begingroup$
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?
$endgroup$
– Embodiment of Ignorance
1 hour ago






2




2




$begingroup$
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.
$endgroup$
– Riker
1 hour ago




$begingroup$
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.
$endgroup$
– Riker
1 hour ago












$begingroup$
You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
$endgroup$
– Adám
1 hour ago




$begingroup$
You may want to add some edge cases, like lists with negative, large-magnitude, unique, or no integers.
$endgroup$
– Adám
1 hour ago












$begingroup$
I have added some answers to the test cases, sorry if I go them wrong
$endgroup$
– MickyT
27 mins ago




$begingroup$
I have added some answers to the test cases, sorry if I go them wrong
$endgroup$
– MickyT
27 mins ago










10 Answers
10






active

oldest

votes


















4












$begingroup$


APL (Dyalog Unicode), 9 bytesSBCS





Anonymous tacit prefix function.



+/{1<≢⍵}⌸


Try it online!



+/ sum of



{}⌸ for each unique element:



1< whether 1 is less than



≢⍵ the count of occurrences






share|improve this answer











$endgroup$





















    2












    $begingroup$


    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)


    Try it online!






    share|improve this answer









    $endgroup$





















      1












      $begingroup$


      C# (Visual C# Interactive Compiler), 40 bytes





      n=>n.GroupBy(c=>c).Where(x=>x.Count()>1)


      Outputs by an IEnumerable<IGrouping<int,int>> with the relevant elements stored in the key.



      Try it online!






      share|improve this answer









      $endgroup$





















        1












        $begingroup$


        Bash + coreutils, 18





        sort|uniq -d|wc -l


        Try it online!






        share|improve this answer









        $endgroup$





















          0












          $begingroup$


          Haskell, 47 bytes





          f[]=0
          f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b


          Try it online!



          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


          Try it online!






          share|improve this answer









          $endgroup$





















            0












            $begingroup$


            J, 11 bytes



            1#.(1<#)/.~


            Try it online!



            Explanation:



                    /.~   group the list by itself
            ( ) for each group
            1<# is the length greater than 1
            1#. sum by base-1 conversion





            share|improve this answer









            $endgroup$





















              0












              $begingroup$

              JavaScript (ES6), 40 bytes





              a=>a.map(o=x=>n+=(o[x]=-~o[x])==2,n=0)|n


              Try it online!






              share|improve this answer









              $endgroup$





















                0












                $begingroup$


                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!





                share









                $endgroup$





















                  0












                  $begingroup$


                  Ruby, 40 bytes





                  ->a{a.select{|x|a.count(x)>1}.uniq.size}


                  Try it online!





                  share









                  $endgroup$





















                    0












                    $begingroup$


                    05AB1E, 4 bytes



                    Ù¢≠O


                    Try it online!
                    or as a Test Suite



                    Explanation



                       O  # sum
                    ≠ # the false values
                    ¢ # in the count
                    Ù # of unique digits in input




                    share











                    $endgroup$













                      Your Answer





                      StackExchange.ifUsing("editor", function () {
                      return StackExchange.using("mathjaxEditing", function () {
                      StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                      StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                      });
                      });
                      }, "mathjax-editing");

                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "200"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: false,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: null,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });






                      jayko03 is a new contributor. Be nice, and check out our Code of Conduct.










                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180302%2fcount-repetitions-of-an-array%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      10 Answers
                      10






                      active

                      oldest

                      votes








                      10 Answers
                      10






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      4












                      $begingroup$


                      APL (Dyalog Unicode), 9 bytesSBCS





                      Anonymous tacit prefix function.



                      +/{1<≢⍵}⌸


                      Try it online!



                      +/ sum of



                      {}⌸ for each unique element:



                      1< whether 1 is less than



                      ≢⍵ the count of occurrences






                      share|improve this answer











                      $endgroup$


















                        4












                        $begingroup$


                        APL (Dyalog Unicode), 9 bytesSBCS





                        Anonymous tacit prefix function.



                        +/{1<≢⍵}⌸


                        Try it online!



                        +/ sum of



                        {}⌸ for each unique element:



                        1< whether 1 is less than



                        ≢⍵ the count of occurrences






                        share|improve this answer











                        $endgroup$
















                          4












                          4








                          4





                          $begingroup$


                          APL (Dyalog Unicode), 9 bytesSBCS





                          Anonymous tacit prefix function.



                          +/{1<≢⍵}⌸


                          Try it online!



                          +/ sum of



                          {}⌸ for each unique element:



                          1< whether 1 is less than



                          ≢⍵ the count of occurrences






                          share|improve this answer











                          $endgroup$




                          APL (Dyalog Unicode), 9 bytesSBCS





                          Anonymous tacit prefix function.



                          +/{1<≢⍵}⌸


                          Try it online!



                          +/ sum of



                          {}⌸ for each unique element:



                          1< whether 1 is less than



                          ≢⍵ the count of occurrences







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 1 hour ago

























                          answered 1 hour ago









                          AdámAdám

                          28.2k274201




                          28.2k274201























                              2












                              $begingroup$


                              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)


                              Try it online!






                              share|improve this answer









                              $endgroup$


















                                2












                                $begingroup$


                                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)


                                Try it online!






                                share|improve this answer









                                $endgroup$
















                                  2












                                  2








                                  2





                                  $begingroup$


                                  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)


                                  Try it online!






                                  share|improve this answer









                                  $endgroup$




                                  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)


                                  Try it online!







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered 1 hour ago









                                  MickyTMickyT

                                  10k21535




                                  10k21535























                                      1












                                      $begingroup$


                                      C# (Visual C# Interactive Compiler), 40 bytes





                                      n=>n.GroupBy(c=>c).Where(x=>x.Count()>1)


                                      Outputs by an IEnumerable<IGrouping<int,int>> with the relevant elements stored in the key.



                                      Try it online!






                                      share|improve this answer









                                      $endgroup$


















                                        1












                                        $begingroup$


                                        C# (Visual C# Interactive Compiler), 40 bytes





                                        n=>n.GroupBy(c=>c).Where(x=>x.Count()>1)


                                        Outputs by an IEnumerable<IGrouping<int,int>> with the relevant elements stored in the key.



                                        Try it online!






                                        share|improve this answer









                                        $endgroup$
















                                          1












                                          1








                                          1





                                          $begingroup$


                                          C# (Visual C# Interactive Compiler), 40 bytes





                                          n=>n.GroupBy(c=>c).Where(x=>x.Count()>1)


                                          Outputs by an IEnumerable<IGrouping<int,int>> with the relevant elements stored in the key.



                                          Try it online!






                                          share|improve this answer









                                          $endgroup$




                                          C# (Visual C# Interactive Compiler), 40 bytes





                                          n=>n.GroupBy(c=>c).Where(x=>x.Count()>1)


                                          Outputs by an IEnumerable<IGrouping<int,int>> with the relevant elements stored in the key.



                                          Try it online!







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered 45 mins ago









                                          Embodiment of IgnoranceEmbodiment of Ignorance

                                          1,120119




                                          1,120119























                                              1












                                              $begingroup$


                                              Bash + coreutils, 18





                                              sort|uniq -d|wc -l


                                              Try it online!






                                              share|improve this answer









                                              $endgroup$


















                                                1












                                                $begingroup$


                                                Bash + coreutils, 18





                                                sort|uniq -d|wc -l


                                                Try it online!






                                                share|improve this answer









                                                $endgroup$
















                                                  1












                                                  1








                                                  1





                                                  $begingroup$


                                                  Bash + coreutils, 18





                                                  sort|uniq -d|wc -l


                                                  Try it online!






                                                  share|improve this answer









                                                  $endgroup$




                                                  Bash + coreutils, 18





                                                  sort|uniq -d|wc -l


                                                  Try it online!







                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered 29 mins ago









                                                  Digital TraumaDigital Trauma

                                                  59.1k787224




                                                  59.1k787224























                                                      0












                                                      $begingroup$


                                                      Haskell, 47 bytes





                                                      f[]=0
                                                      f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b


                                                      Try it online!



                                                      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


                                                      Try it online!






                                                      share|improve this answer









                                                      $endgroup$


















                                                        0












                                                        $begingroup$


                                                        Haskell, 47 bytes





                                                        f[]=0
                                                        f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b


                                                        Try it online!



                                                        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


                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$
















                                                          0












                                                          0








                                                          0





                                                          $begingroup$


                                                          Haskell, 47 bytes





                                                          f[]=0
                                                          f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b


                                                          Try it online!



                                                          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


                                                          Try it online!






                                                          share|improve this answer









                                                          $endgroup$




                                                          Haskell, 47 bytes





                                                          f[]=0
                                                          f(a:b)|x<-filter(/=a)b,x/=b=1+f x|1>0=f b


                                                          Try it online!



                                                          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


                                                          Try it online!







                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered 19 mins ago









                                                          Sriotchilism O'ZaicSriotchilism O'Zaic

                                                          35.1k10159369




                                                          35.1k10159369























                                                              0












                                                              $begingroup$


                                                              J, 11 bytes



                                                              1#.(1<#)/.~


                                                              Try it online!



                                                              Explanation:



                                                                      /.~   group the list by itself
                                                              ( ) for each group
                                                              1<# is the length greater than 1
                                                              1#. sum by base-1 conversion





                                                              share|improve this answer









                                                              $endgroup$


















                                                                0












                                                                $begingroup$


                                                                J, 11 bytes



                                                                1#.(1<#)/.~


                                                                Try it online!



                                                                Explanation:



                                                                        /.~   group the list by itself
                                                                ( ) for each group
                                                                1<# is the length greater than 1
                                                                1#. sum by base-1 conversion





                                                                share|improve this answer









                                                                $endgroup$
















                                                                  0












                                                                  0








                                                                  0





                                                                  $begingroup$


                                                                  J, 11 bytes



                                                                  1#.(1<#)/.~


                                                                  Try it online!



                                                                  Explanation:



                                                                          /.~   group the list by itself
                                                                  ( ) for each group
                                                                  1<# is the length greater than 1
                                                                  1#. sum by base-1 conversion





                                                                  share|improve this answer









                                                                  $endgroup$




                                                                  J, 11 bytes



                                                                  1#.(1<#)/.~


                                                                  Try it online!



                                                                  Explanation:



                                                                          /.~   group the list by itself
                                                                  ( ) for each group
                                                                  1<# is the length greater than 1
                                                                  1#. sum by base-1 conversion






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered 18 mins ago









                                                                  Galen IvanovGalen Ivanov

                                                                  6,80711033




                                                                  6,80711033























                                                                      0












                                                                      $begingroup$

                                                                      JavaScript (ES6), 40 bytes





                                                                      a=>a.map(o=x=>n+=(o[x]=-~o[x])==2,n=0)|n


                                                                      Try it online!






                                                                      share|improve this answer









                                                                      $endgroup$


















                                                                        0












                                                                        $begingroup$

                                                                        JavaScript (ES6), 40 bytes





                                                                        a=>a.map(o=x=>n+=(o[x]=-~o[x])==2,n=0)|n


                                                                        Try it online!






                                                                        share|improve this answer









                                                                        $endgroup$
















                                                                          0












                                                                          0








                                                                          0





                                                                          $begingroup$

                                                                          JavaScript (ES6), 40 bytes





                                                                          a=>a.map(o=x=>n+=(o[x]=-~o[x])==2,n=0)|n


                                                                          Try it online!






                                                                          share|improve this answer









                                                                          $endgroup$



                                                                          JavaScript (ES6), 40 bytes





                                                                          a=>a.map(o=x=>n+=(o[x]=-~o[x])==2,n=0)|n


                                                                          Try it online!







                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered 10 mins ago









                                                                          ArnauldArnauld

                                                                          76.7k693322




                                                                          76.7k693322























                                                                              0












                                                                              $begingroup$


                                                                              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!





                                                                              share









                                                                              $endgroup$


















                                                                                0












                                                                                $begingroup$


                                                                                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!





                                                                                share









                                                                                $endgroup$
















                                                                                  0












                                                                                  0








                                                                                  0





                                                                                  $begingroup$


                                                                                  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!





                                                                                  share









                                                                                  $endgroup$




                                                                                  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!






                                                                                  share











                                                                                  share


                                                                                  share










                                                                                  answered 7 mins ago









                                                                                  Mike ShlantaMike Shlanta

                                                                                  357310




                                                                                  357310























                                                                                      0












                                                                                      $begingroup$


                                                                                      Ruby, 40 bytes





                                                                                      ->a{a.select{|x|a.count(x)>1}.uniq.size}


                                                                                      Try it online!





                                                                                      share









                                                                                      $endgroup$


















                                                                                        0












                                                                                        $begingroup$


                                                                                        Ruby, 40 bytes





                                                                                        ->a{a.select{|x|a.count(x)>1}.uniq.size}


                                                                                        Try it online!





                                                                                        share









                                                                                        $endgroup$
















                                                                                          0












                                                                                          0








                                                                                          0





                                                                                          $begingroup$


                                                                                          Ruby, 40 bytes





                                                                                          ->a{a.select{|x|a.count(x)>1}.uniq.size}


                                                                                          Try it online!





                                                                                          share









                                                                                          $endgroup$




                                                                                          Ruby, 40 bytes





                                                                                          ->a{a.select{|x|a.count(x)>1}.uniq.size}


                                                                                          Try it online!






                                                                                          share











                                                                                          share


                                                                                          share










                                                                                          answered 36 secs ago









                                                                                          Kirill L.Kirill L.

                                                                                          4,5251523




                                                                                          4,5251523























                                                                                              0












                                                                                              $begingroup$


                                                                                              05AB1E, 4 bytes



                                                                                              Ù¢≠O


                                                                                              Try it online!
                                                                                              or as a Test Suite



                                                                                              Explanation



                                                                                                 O  # sum
                                                                                              ≠ # the false values
                                                                                              ¢ # in the count
                                                                                              Ù # of unique digits in input




                                                                                              share











                                                                                              $endgroup$


















                                                                                                0












                                                                                                $begingroup$


                                                                                                05AB1E, 4 bytes



                                                                                                Ù¢≠O


                                                                                                Try it online!
                                                                                                or as a Test Suite



                                                                                                Explanation



                                                                                                   O  # sum
                                                                                                ≠ # the false values
                                                                                                ¢ # in the count
                                                                                                Ù # of unique digits in input




                                                                                                share











                                                                                                $endgroup$
















                                                                                                  0












                                                                                                  0








                                                                                                  0





                                                                                                  $begingroup$


                                                                                                  05AB1E, 4 bytes



                                                                                                  Ù¢≠O


                                                                                                  Try it online!
                                                                                                  or as a Test Suite



                                                                                                  Explanation



                                                                                                     O  # sum
                                                                                                  ≠ # the false values
                                                                                                  ¢ # in the count
                                                                                                  Ù # of unique digits in input




                                                                                                  share











                                                                                                  $endgroup$




                                                                                                  05AB1E, 4 bytes



                                                                                                  Ù¢≠O


                                                                                                  Try it online!
                                                                                                  or as a Test Suite



                                                                                                  Explanation



                                                                                                     O  # sum
                                                                                                  ≠ # the false values
                                                                                                  ¢ # in the count
                                                                                                  Ù # of unique digits in input





                                                                                                  share













                                                                                                  share


                                                                                                  share








                                                                                                  edited 12 secs ago

























                                                                                                  answered 5 mins ago









                                                                                                  EmignaEmigna

                                                                                                  46.5k432142




                                                                                                  46.5k432142






















                                                                                                      jayko03 is a new contributor. Be nice, and check out our Code of Conduct.










                                                                                                      draft saved

                                                                                                      draft discarded


















                                                                                                      jayko03 is a new contributor. Be nice, and check out our Code of Conduct.













                                                                                                      jayko03 is a new contributor. Be nice, and check out our Code of Conduct.












                                                                                                      jayko03 is a new contributor. Be nice, and check out our Code of Conduct.
















                                                                                                      If this is an answer to a challenge…




                                                                                                      • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                      • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                        Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                      • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                      More generally…




                                                                                                      • …Please make sure to answer the question and provide sufficient detail.


                                                                                                      • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                      draft saved


                                                                                                      draft discarded














                                                                                                      StackExchange.ready(
                                                                                                      function () {
                                                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180302%2fcount-repetitions-of-an-array%23new-answer', 'question_page');
                                                                                                      }
                                                                                                      );

                                                                                                      Post as a guest















                                                                                                      Required, but never shown





















































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown

































                                                                                                      Required, but never shown














                                                                                                      Required, but never shown












                                                                                                      Required, but never shown







                                                                                                      Required, but never shown







                                                                                                      Popular posts from this blog

                                                                                                      Szabolcs (Ungheria) Altri progetti | Menu di navigazione48°10′14.56″N 21°29′33.14″E /...

                                                                                                      Discografia di Klaus Schulze Indice Album in studio | Album dal vivo | Singoli | Antologie | Colonne...

                                                                                                      How to make inet_server_addr() return localhost in spite of ::1/128RETURN NEXT in Postgres FunctionConnect to...