Enumerate each series of identical numbers in-place












17














Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.



Examples



/



[42][0]/[1]



[7,7,7][0,1,2]/[1,2,3]



[10,20,30][0,0,0]/[1,1,1]



[5,12,10,12,12,10][0,0,0,1,2,1]/[1,1,1,2,3,2]



[2,7,1,8,2,8,1,8,2,8][0,0,0,0,1,1,1,2,2,3]/[1,1,1,1,2,2,2,3,3,4]



[3,1,4,1,5,9,2,6,5,3,5,9][0,0,0,1,0,0,0,0,1,1,2,1]/[1,1,1,2,1,1,1,1,2,2,3,2]










share|improve this question


















  • 2




    So basically the number of times it has appeared the sequence so far?
    – Jo King
    yesterday






  • 1




    @JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
    – Adám
    yesterday
















17














Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.



Examples



/



[42][0]/[1]



[7,7,7][0,1,2]/[1,2,3]



[10,20,30][0,0,0]/[1,1,1]



[5,12,10,12,12,10][0,0,0,1,2,1]/[1,1,1,2,3,2]



[2,7,1,8,2,8,1,8,2,8][0,0,0,0,1,1,1,2,2,3]/[1,1,1,1,2,2,2,3,3,4]



[3,1,4,1,5,9,2,6,5,3,5,9][0,0,0,1,0,0,0,0,1,1,2,1]/[1,1,1,2,1,1,1,1,2,2,3,2]










share|improve this question


















  • 2




    So basically the number of times it has appeared the sequence so far?
    – Jo King
    yesterday






  • 1




    @JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
    – Adám
    yesterday














17












17








17







Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.



Examples



/



[42][0]/[1]



[7,7,7][0,1,2]/[1,2,3]



[10,20,30][0,0,0]/[1,1,1]



[5,12,10,12,12,10][0,0,0,1,2,1]/[1,1,1,2,3,2]



[2,7,1,8,2,8,1,8,2,8][0,0,0,0,1,1,1,2,2,3]/[1,1,1,1,2,2,2,3,3,4]



[3,1,4,1,5,9,2,6,5,3,5,9][0,0,0,1,0,0,0,0,1,1,2,1]/[1,1,1,2,1,1,1,1,2,2,3,2]










share|improve this question













Given a list of strictly positive integers, go through each distinct number and replace all occurrences of it with successive indices (zero or one based) of a new series.



Examples



/



[42][0]/[1]



[7,7,7][0,1,2]/[1,2,3]



[10,20,30][0,0,0]/[1,1,1]



[5,12,10,12,12,10][0,0,0,1,2,1]/[1,1,1,2,3,2]



[2,7,1,8,2,8,1,8,2,8][0,0,0,0,1,1,1,2,2,3]/[1,1,1,1,2,2,2,3,3,4]



[3,1,4,1,5,9,2,6,5,3,5,9][0,0,0,1,0,0,0,0,1,1,2,1]/[1,1,1,2,1,1,1,1,2,2,3,2]







code-golf number integer sorting substitution






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked yesterday









AdámAdám

29k269192




29k269192








  • 2




    So basically the number of times it has appeared the sequence so far?
    – Jo King
    yesterday






  • 1




    @JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
    – Adám
    yesterday














  • 2




    So basically the number of times it has appeared the sequence so far?
    – Jo King
    yesterday






  • 1




    @JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
    – Adám
    yesterday








2




2




So basically the number of times it has appeared the sequence so far?
– Jo King
yesterday




So basically the number of times it has appeared the sequence so far?
– Jo King
yesterday




1




1




@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
yesterday




@JoKing Yes, that's another way to state it, but "so far" implies zero-based, and "until and including this" implies one-based. I wanted to keep the choice.
– Adám
yesterday










27 Answers
27






active

oldest

votes


















19














JavaScript (ES6), 26 bytes



1-indexed.





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


Try it online!



Commented



a =>                // a = input array
a.map(o = // assign the callback function of map() to the variable o, so that
// we have an object that can be used to store the counters
x => // for each value x in a:
o[x] = -~o[x] // increment o[x] and yield the result
// the '-~' syntax allows to go from undefined to 1
) // end of map()





share|improve this answer



















  • 1




    I have no idea how that works, but it sure looks elegant.
    – Adám
    yesterday










  • I've not seen -~ before - that is an absolute gem.
    – DaveMongoose
    yesterday












  • Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
    – user202729
    yesterday












  • @DaveMongoose Tips for golfing in JavaScript
    – user202729
    yesterday












  • Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
    – user202729
    yesterday



















6















MATL, 4 bytes



&=Rs


This solution is 1-based



Try it out at MATL Online!



Explanation



Uses [1,2,3,2] as an example



    # Implicitly grab the input array of length N
#
# [1,2,3,2]
#
&= # Create an N x N boolean matrix by performing an element-wise comparison
# between the original array and its transpose:
#
# 1 2 3 2
# -------
# 1 | 1 0 0 0
# 2 | 0 1 0 1
# 3 | 0 0 1 0
# 2 | 0 1 0 1
#
R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
#
# [1 0 0 0
# 0 1 0 1
# 0 0 1 0
# 0 0 0 1]
#
s # Compute the sum down the columns
#
# [1,1,1,2]
#
# Implicitly display the result





share|improve this answer



















  • 1




    ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
    – Giuseppe
    yesterday



















5















APL (Dyalog Unicode), 7 bytes





Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.



+/¨⊢=,


Try it online!



Explanation



The 10-byte non-tacit version will be easier to explain first



{+/¨⍵=,⍵}

{ } A user-defined function, a dfn
,⍵ The list of prefixes of our input list ⍵
(⍵ more generally means the right argument of a dfn)
is 'scan' which both gives us our prefixes
and applies ,/ over each prefix, which keeps each prefix as-is
⍵= Checks each element of ⍵ against its corresponding prefix
This checks each prefix for occurrences of the last element of that prefix
This gives us several lists of 0s and 1s
+/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for


The tacit version does three things




  • First, it removes the instance of used in ,⍵ as , on the right by itself can implicitly figure out that it's supposed to operate on the right argument.

  • Second, for ⍵=, we replace the with , which stands for right argument

  • Third, now that we have no explicit arguments (in this case, ), we can remove the braces {} as tacit functions do not use them






share|improve this answer































    5















    J, 7 bytes



    1#.]=]


    Try it online!



    1-indexed.



    Explanation:



    ] all the prefixes (filled with zeros, but there won't be any 0s in the input):
    ] 5 12 10 12 12 10
    5 0 0 0 0 0
    5 12 0 0 0 0
    5 12 10 0 0 0
    5 12 10 12 0 0
    5 12 10 12 12 0
    5 12 10 12 12 10

    ]= is each number from the input equal to the prefix:
    (]=]) 5 12 10 12 12 10
    1 0 0 0 0 0
    0 1 0 0 0 0
    0 0 1 0 0 0
    0 1 0 1 0 0
    0 1 0 1 1 0
    0 0 1 0 0 1

    1#. sum each row:
    (1#.]=]) 5 12 10 12 12 10
    1 1 1 2 3 2



    K (oK), 11 bytes



    {+/'x=',x}


    Try it online!






    share|improve this answer



















    • 1




      Heh, you're happy that I made the data strictly positive…
      – Adám
      yesterday










    • @Adám Yes, otherwise I'd need to box the prefixes :)
      – Galen Ivanov
      yesterday



















    4















    Python 2, 48 bytes





    lambda a:[a[:i].count(v)for i,v in enumerate(a)]


    Try it online!






    share|improve this answer





























      3















      05AB1E, 4 bytes



      ηε¤¢


      Try it online!
      or as a Test Suite



      Explanation



      ηε     # apply to each prefix of the input list
      ¤¢ # count occurrences of the last element





      share|improve this answer





























        3















        AWK, 15



        {print a[$1]++}


        Try it online!



        The above does zero-based indexing. If you prefer one-based indexing, its a simple change:



        {print ++a[$1]}


        Try it online!






        share|improve this answer































          2















          Python 2, 47 43 bytes





          f=lambda a:a and f(a[:-1])+[a.count(a[-1])]


          Try it online!



          A recursive 'one-based' solution.






          share|improve this answer































            2















            Jelly, 4 bytes



            ċṪ$Ƥ


            Try it online!



            For each prefix of the input list, it counts the number of occurrences of its last element in itself.






            share|improve this answer





















            • Alternatively the old-school ;ċ" is also 4.
              – Jonathan Allan
              yesterday



















            2















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





            x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))


            Try it online!






            share|improve this answer























            • 22 bytes
              – LiefdeWen
              yesterday










            • You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
              – Kevin Cruijssen
              yesterday






            • 1




              @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
              – dana
              yesterday



















            2














            Ruby, 35 bytes



            ->a{f=Hash.new 0;a.map{|v|f[v]+=1}}


            It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.



            Some other, fun options that unfortunately weren't quite short enough:



            ->a{a.dup.map{a.count a.pop}.reverse}   # 37
            ->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38





            share|improve this answer





























              2















              Perl 6, 15 bytes





              *>>.&{%.{$_}++}


              Try it online!



              You can move the ++ to before the % for a one based index.



              Explanation:



              *>>.&{        }  # Map the input to
              % # An anonymous hash
              .{$_} # The current element indexed
              ++ # Incremented





              share|improve this answer































                1















                R, 41 bytes





                function(x)diag(diffinv(outer(x,x,"==")))


                Try it online!



                Oddly, returning a zero-based index is shorter in R.






                share|improve this answer





















                • Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                  – Sumner18
                  yesterday










                • @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                  – Giuseppe
                  yesterday












                • thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                  – Sumner18
                  yesterday



















                1















                Java (JDK), 76 bytes





                a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}


                Try it online!



                Credits




                • -2 bytes thanks to Kevin Cruijssen






                share|improve this answer



















                • 1




                  -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                  – Kevin Cruijssen
                  yesterday



















                1















                R, 62 43 bytes





                x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z


                -19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation



                Original



                x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z


                I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.



                r<-table(x) counts the number of times each number appears and stores it in r, for future reference



                names() gets the values of each unique entry in the table, and we iterate over these names with a for loop.



                The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)



                Try it online!






                share|improve this answer























                • you can remove the which() to save 7 bytes.
                  – Giuseppe
                  yesterday










                • Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                  – Giuseppe
                  yesterday





















                1















                Ruby, 34 bytes





                ->a{r=;a.map{|x|(r<<x).count x}}


                Try it online!






                share|improve this answer





















                • I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                  – DaveMongoose
                  19 hours ago





















                1














                bash, 37 bytes or 24 bytes



                f()(for x;{ r+=$[a[x]++] ;};echo $r)


                TIO



                if valid, there is also this variation, as suggested by DigitalTrauma



                for x;{ echo $[a[x]++];}


                TIO






                share|improve this answer



















                • 1




                  Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                  – Digital Trauma
                  yesterday










                • @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                  – Nahuel Fouilleul
                  21 hours ago






                • 1




                  @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                  – ASCII-only
                  21 hours ago



















                0















                Retina 0.8.2, 30 bytes



                b(d+)b(?<=(b1b.*?)+)
                $#2


                Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.






                share|improve this answer





























                  0














                  Batch, 61 bytes



                  @setlocal
                  @for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%


                  1-indexed. Because variable substitution happens before parsing, the set/a command ends up incrementing the variable name given by concatenating the letter c with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).






                  share|improve this answer





























                    0














                    awk (46 bytes)



                    {delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}


                    TIO






                    share|improve this answer





























                      0















                      Tcl, 48 bytes



                      proc C L {lmap n $L {dict g [dict inc D $n] $n}}


                      Try it online!






                      share|improve this answer































                        0














                        Japt, 8 bytes



                        £¯YÄ è¶X


                        Try it here



                        £¯YÄ è¶X
                        :Implicit input of array U
                        £ :Map each X at 0-based index Y
                        ¯ : Slice U to index
                        YÄ : Y+1
                        è : Count the elements
                        ¶X : Equal to X





                        share|improve this answer































                          0















                          Haskell, 44 bytes





                          (#)
                          x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
                          _#e=e


                          Try it online!



                          Explanation



                          Traverses the list from left to right keeping the list x of visited elements, initially :



                          For every encounter of a y count all equal elements in the list x.






                          share|improve this answer





























                            0














                            Haxe, 58 bytes



                            l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};


                            (Requires arrow functions, so 4.0+)



                            var x=[0=>0] declares a new IntMap, with 0 as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null to a number, hence the explicit check to make sure each key is in the map before incrementing.



                            Also a cheeky rip off based on the JS answer:



                            Haxe (JS target), 41 bytes



                            l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};


                            Try both online






                            share|improve this answer





























                              0














                              GO 121 Bytes (Not included new lines and tabs)



                              func cg(a int) int{
                              var m = make(map[int]int)
                              var r = make(int, len(a))
                              for i,v := range a{
                              r[i] = m[v]
                              m[v]++
                              }
                              return r
                              }


                              Accepts integer array and returns integer array.






                              share|improve this answer








                              New contributor




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














                              • 3




                                Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                – Adám
                                19 hours ago



















                              0














                              C++,137 bytes
                              //v is input , ov is output ; //example to populate v: vector v{7,8,7};



                              vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});





                              share|improve this answer










                              New contributor




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


















                              • I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                – Stephen
                                yesterday






                              • 1




                                I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                – Jo King
                                19 hours ago



















                              0















                              Python 2, 44 bytes





                              a=
                              for x in input():print a.count(x);a+=x,


                              Try it online!



                              The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.






                              share|improve this answer





















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


                                }
                                });














                                draft saved

                                draft discarded


















                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178500%2fenumerate-each-series-of-identical-numbers-in-place%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown

























                                27 Answers
                                27






                                active

                                oldest

                                votes








                                27 Answers
                                27






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes









                                19














                                JavaScript (ES6), 26 bytes



                                1-indexed.





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


                                Try it online!



                                Commented



                                a =>                // a = input array
                                a.map(o = // assign the callback function of map() to the variable o, so that
                                // we have an object that can be used to store the counters
                                x => // for each value x in a:
                                o[x] = -~o[x] // increment o[x] and yield the result
                                // the '-~' syntax allows to go from undefined to 1
                                ) // end of map()





                                share|improve this answer



















                                • 1




                                  I have no idea how that works, but it sure looks elegant.
                                  – Adám
                                  yesterday










                                • I've not seen -~ before - that is an absolute gem.
                                  – DaveMongoose
                                  yesterday












                                • Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                  – user202729
                                  yesterday












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  yesterday












                                • Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                  – user202729
                                  yesterday
















                                19














                                JavaScript (ES6), 26 bytes



                                1-indexed.





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


                                Try it online!



                                Commented



                                a =>                // a = input array
                                a.map(o = // assign the callback function of map() to the variable o, so that
                                // we have an object that can be used to store the counters
                                x => // for each value x in a:
                                o[x] = -~o[x] // increment o[x] and yield the result
                                // the '-~' syntax allows to go from undefined to 1
                                ) // end of map()





                                share|improve this answer



















                                • 1




                                  I have no idea how that works, but it sure looks elegant.
                                  – Adám
                                  yesterday










                                • I've not seen -~ before - that is an absolute gem.
                                  – DaveMongoose
                                  yesterday












                                • Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                  – user202729
                                  yesterday












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  yesterday












                                • Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                  – user202729
                                  yesterday














                                19












                                19








                                19






                                JavaScript (ES6), 26 bytes



                                1-indexed.





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


                                Try it online!



                                Commented



                                a =>                // a = input array
                                a.map(o = // assign the callback function of map() to the variable o, so that
                                // we have an object that can be used to store the counters
                                x => // for each value x in a:
                                o[x] = -~o[x] // increment o[x] and yield the result
                                // the '-~' syntax allows to go from undefined to 1
                                ) // end of map()





                                share|improve this answer














                                JavaScript (ES6), 26 bytes



                                1-indexed.





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


                                Try it online!



                                Commented



                                a =>                // a = input array
                                a.map(o = // assign the callback function of map() to the variable o, so that
                                // we have an object that can be used to store the counters
                                x => // for each value x in a:
                                o[x] = -~o[x] // increment o[x] and yield the result
                                // the '-~' syntax allows to go from undefined to 1
                                ) // end of map()






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited yesterday

























                                answered yesterday









                                ArnauldArnauld

                                72.9k689307




                                72.9k689307








                                • 1




                                  I have no idea how that works, but it sure looks elegant.
                                  – Adám
                                  yesterday










                                • I've not seen -~ before - that is an absolute gem.
                                  – DaveMongoose
                                  yesterday












                                • Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                  – user202729
                                  yesterday












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  yesterday












                                • Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                  – user202729
                                  yesterday














                                • 1




                                  I have no idea how that works, but it sure looks elegant.
                                  – Adám
                                  yesterday










                                • I've not seen -~ before - that is an absolute gem.
                                  – DaveMongoose
                                  yesterday












                                • Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                  – user202729
                                  yesterday












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  yesterday












                                • Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                  – user202729
                                  yesterday








                                1




                                1




                                I have no idea how that works, but it sure looks elegant.
                                – Adám
                                yesterday




                                I have no idea how that works, but it sure looks elegant.
                                – Adám
                                yesterday












                                I've not seen -~ before - that is an absolute gem.
                                – DaveMongoose
                                yesterday






                                I've not seen -~ before - that is an absolute gem.
                                – DaveMongoose
                                yesterday














                                Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                – user202729
                                yesterday






                                Alternatively, it's possible to use a to store the values, but it's required to -/~ the index so no byte is saved.
                                – user202729
                                yesterday














                                @DaveMongoose Tips for golfing in JavaScript
                                – user202729
                                yesterday






                                @DaveMongoose Tips for golfing in JavaScript
                                – user202729
                                yesterday














                                Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                – user202729
                                yesterday




                                Too bad this isn't C++, otherwise something like a=>a.map(x=>++(a[-x]|=0)) would save a byte.
                                – user202729
                                yesterday











                                6















                                MATL, 4 bytes



                                &=Rs


                                This solution is 1-based



                                Try it out at MATL Online!



                                Explanation



                                Uses [1,2,3,2] as an example



                                    # Implicitly grab the input array of length N
                                #
                                # [1,2,3,2]
                                #
                                &= # Create an N x N boolean matrix by performing an element-wise comparison
                                # between the original array and its transpose:
                                #
                                # 1 2 3 2
                                # -------
                                # 1 | 1 0 0 0
                                # 2 | 0 1 0 1
                                # 3 | 0 0 1 0
                                # 2 | 0 1 0 1
                                #
                                R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
                                #
                                # [1 0 0 0
                                # 0 1 0 1
                                # 0 0 1 0
                                # 0 0 0 1]
                                #
                                s # Compute the sum down the columns
                                #
                                # [1,1,1,2]
                                #
                                # Implicitly display the result





                                share|improve this answer



















                                • 1




                                  ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                  – Giuseppe
                                  yesterday
















                                6















                                MATL, 4 bytes



                                &=Rs


                                This solution is 1-based



                                Try it out at MATL Online!



                                Explanation



                                Uses [1,2,3,2] as an example



                                    # Implicitly grab the input array of length N
                                #
                                # [1,2,3,2]
                                #
                                &= # Create an N x N boolean matrix by performing an element-wise comparison
                                # between the original array and its transpose:
                                #
                                # 1 2 3 2
                                # -------
                                # 1 | 1 0 0 0
                                # 2 | 0 1 0 1
                                # 3 | 0 0 1 0
                                # 2 | 0 1 0 1
                                #
                                R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
                                #
                                # [1 0 0 0
                                # 0 1 0 1
                                # 0 0 1 0
                                # 0 0 0 1]
                                #
                                s # Compute the sum down the columns
                                #
                                # [1,1,1,2]
                                #
                                # Implicitly display the result





                                share|improve this answer



















                                • 1




                                  ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                  – Giuseppe
                                  yesterday














                                6












                                6








                                6







                                MATL, 4 bytes



                                &=Rs


                                This solution is 1-based



                                Try it out at MATL Online!



                                Explanation



                                Uses [1,2,3,2] as an example



                                    # Implicitly grab the input array of length N
                                #
                                # [1,2,3,2]
                                #
                                &= # Create an N x N boolean matrix by performing an element-wise comparison
                                # between the original array and its transpose:
                                #
                                # 1 2 3 2
                                # -------
                                # 1 | 1 0 0 0
                                # 2 | 0 1 0 1
                                # 3 | 0 0 1 0
                                # 2 | 0 1 0 1
                                #
                                R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
                                #
                                # [1 0 0 0
                                # 0 1 0 1
                                # 0 0 1 0
                                # 0 0 0 1]
                                #
                                s # Compute the sum down the columns
                                #
                                # [1,1,1,2]
                                #
                                # Implicitly display the result





                                share|improve this answer















                                MATL, 4 bytes



                                &=Rs


                                This solution is 1-based



                                Try it out at MATL Online!



                                Explanation



                                Uses [1,2,3,2] as an example



                                    # Implicitly grab the input array of length N
                                #
                                # [1,2,3,2]
                                #
                                &= # Create an N x N boolean matrix by performing an element-wise comparison
                                # between the original array and its transpose:
                                #
                                # 1 2 3 2
                                # -------
                                # 1 | 1 0 0 0
                                # 2 | 0 1 0 1
                                # 3 | 0 0 1 0
                                # 2 | 0 1 0 1
                                #
                                R # Take the upper-triangular portion of this matrix (sets below-diagonal to 0)
                                #
                                # [1 0 0 0
                                # 0 1 0 1
                                # 0 0 1 0
                                # 0 0 0 1]
                                #
                                s # Compute the sum down the columns
                                #
                                # [1,1,1,2]
                                #
                                # Implicitly display the result






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited yesterday

























                                answered yesterday









                                SueverSuever

                                9,6021345




                                9,6021345








                                • 1




                                  ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                  – Giuseppe
                                  yesterday














                                • 1




                                  ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                  – Giuseppe
                                  yesterday








                                1




                                1




                                ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                – Giuseppe
                                yesterday




                                ah, I knew there was an old problem that made me think of something similar, it's Unique is Cheap, and the MATL solution there is one character different!
                                – Giuseppe
                                yesterday











                                5















                                APL (Dyalog Unicode), 7 bytes





                                Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.



                                +/¨⊢=,


                                Try it online!



                                Explanation



                                The 10-byte non-tacit version will be easier to explain first



                                {+/¨⍵=,⍵}

                                { } A user-defined function, a dfn
                                ,⍵ The list of prefixes of our input list ⍵
                                (⍵ more generally means the right argument of a dfn)
                                is 'scan' which both gives us our prefixes
                                and applies ,/ over each prefix, which keeps each prefix as-is
                                ⍵= Checks each element of ⍵ against its corresponding prefix
                                This checks each prefix for occurrences of the last element of that prefix
                                This gives us several lists of 0s and 1s
                                +/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for


                                The tacit version does three things




                                • First, it removes the instance of used in ,⍵ as , on the right by itself can implicitly figure out that it's supposed to operate on the right argument.

                                • Second, for ⍵=, we replace the with , which stands for right argument

                                • Third, now that we have no explicit arguments (in this case, ), we can remove the braces {} as tacit functions do not use them






                                share|improve this answer




























                                  5















                                  APL (Dyalog Unicode), 7 bytes





                                  Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.



                                  +/¨⊢=,


                                  Try it online!



                                  Explanation



                                  The 10-byte non-tacit version will be easier to explain first



                                  {+/¨⍵=,⍵}

                                  { } A user-defined function, a dfn
                                  ,⍵ The list of prefixes of our input list ⍵
                                  (⍵ more generally means the right argument of a dfn)
                                  is 'scan' which both gives us our prefixes
                                  and applies ,/ over each prefix, which keeps each prefix as-is
                                  ⍵= Checks each element of ⍵ against its corresponding prefix
                                  This checks each prefix for occurrences of the last element of that prefix
                                  This gives us several lists of 0s and 1s
                                  +/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for


                                  The tacit version does three things




                                  • First, it removes the instance of used in ,⍵ as , on the right by itself can implicitly figure out that it's supposed to operate on the right argument.

                                  • Second, for ⍵=, we replace the with , which stands for right argument

                                  • Third, now that we have no explicit arguments (in this case, ), we can remove the braces {} as tacit functions do not use them






                                  share|improve this answer


























                                    5












                                    5








                                    5







                                    APL (Dyalog Unicode), 7 bytes





                                    Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.



                                    +/¨⊢=,


                                    Try it online!



                                    Explanation



                                    The 10-byte non-tacit version will be easier to explain first



                                    {+/¨⍵=,⍵}

                                    { } A user-defined function, a dfn
                                    ,⍵ The list of prefixes of our input list ⍵
                                    (⍵ more generally means the right argument of a dfn)
                                    is 'scan' which both gives us our prefixes
                                    and applies ,/ over each prefix, which keeps each prefix as-is
                                    ⍵= Checks each element of ⍵ against its corresponding prefix
                                    This checks each prefix for occurrences of the last element of that prefix
                                    This gives us several lists of 0s and 1s
                                    +/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for


                                    The tacit version does three things




                                    • First, it removes the instance of used in ,⍵ as , on the right by itself can implicitly figure out that it's supposed to operate on the right argument.

                                    • Second, for ⍵=, we replace the with , which stands for right argument

                                    • Third, now that we have no explicit arguments (in this case, ), we can remove the braces {} as tacit functions do not use them






                                    share|improve this answer















                                    APL (Dyalog Unicode), 7 bytes





                                    Many, many thanks to H.PWiz, Adám and dzaima for all their help in debugging and correcting this.



                                    +/¨⊢=,


                                    Try it online!



                                    Explanation



                                    The 10-byte non-tacit version will be easier to explain first



                                    {+/¨⍵=,⍵}

                                    { } A user-defined function, a dfn
                                    ,⍵ The list of prefixes of our input list ⍵
                                    (⍵ more generally means the right argument of a dfn)
                                    is 'scan' which both gives us our prefixes
                                    and applies ,/ over each prefix, which keeps each prefix as-is
                                    ⍵= Checks each element of ⍵ against its corresponding prefix
                                    This checks each prefix for occurrences of the last element of that prefix
                                    This gives us several lists of 0s and 1s
                                    +/¨ This sums over each list of 0s and 1s to give us the enumeration we are looking for


                                    The tacit version does three things




                                    • First, it removes the instance of used in ,⍵ as , on the right by itself can implicitly figure out that it's supposed to operate on the right argument.

                                    • Second, for ⍵=, we replace the with , which stands for right argument

                                    • Third, now that we have no explicit arguments (in this case, ), we can remove the braces {} as tacit functions do not use them







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited yesterday

























                                    answered yesterday









                                    Sherlock9Sherlock9

                                    7,86411859




                                    7,86411859























                                        5















                                        J, 7 bytes



                                        1#.]=]


                                        Try it online!



                                        1-indexed.



                                        Explanation:



                                        ] all the prefixes (filled with zeros, but there won't be any 0s in the input):
                                        ] 5 12 10 12 12 10
                                        5 0 0 0 0 0
                                        5 12 0 0 0 0
                                        5 12 10 0 0 0
                                        5 12 10 12 0 0
                                        5 12 10 12 12 0
                                        5 12 10 12 12 10

                                        ]= is each number from the input equal to the prefix:
                                        (]=]) 5 12 10 12 12 10
                                        1 0 0 0 0 0
                                        0 1 0 0 0 0
                                        0 0 1 0 0 0
                                        0 1 0 1 0 0
                                        0 1 0 1 1 0
                                        0 0 1 0 0 1

                                        1#. sum each row:
                                        (1#.]=]) 5 12 10 12 12 10
                                        1 1 1 2 3 2



                                        K (oK), 11 bytes



                                        {+/'x=',x}


                                        Try it online!






                                        share|improve this answer



















                                        • 1




                                          Heh, you're happy that I made the data strictly positive…
                                          – Adám
                                          yesterday










                                        • @Adám Yes, otherwise I'd need to box the prefixes :)
                                          – Galen Ivanov
                                          yesterday
















                                        5















                                        J, 7 bytes



                                        1#.]=]


                                        Try it online!



                                        1-indexed.



                                        Explanation:



                                        ] all the prefixes (filled with zeros, but there won't be any 0s in the input):
                                        ] 5 12 10 12 12 10
                                        5 0 0 0 0 0
                                        5 12 0 0 0 0
                                        5 12 10 0 0 0
                                        5 12 10 12 0 0
                                        5 12 10 12 12 0
                                        5 12 10 12 12 10

                                        ]= is each number from the input equal to the prefix:
                                        (]=]) 5 12 10 12 12 10
                                        1 0 0 0 0 0
                                        0 1 0 0 0 0
                                        0 0 1 0 0 0
                                        0 1 0 1 0 0
                                        0 1 0 1 1 0
                                        0 0 1 0 0 1

                                        1#. sum each row:
                                        (1#.]=]) 5 12 10 12 12 10
                                        1 1 1 2 3 2



                                        K (oK), 11 bytes



                                        {+/'x=',x}


                                        Try it online!






                                        share|improve this answer



















                                        • 1




                                          Heh, you're happy that I made the data strictly positive…
                                          – Adám
                                          yesterday










                                        • @Adám Yes, otherwise I'd need to box the prefixes :)
                                          – Galen Ivanov
                                          yesterday














                                        5












                                        5








                                        5







                                        J, 7 bytes



                                        1#.]=]


                                        Try it online!



                                        1-indexed.



                                        Explanation:



                                        ] all the prefixes (filled with zeros, but there won't be any 0s in the input):
                                        ] 5 12 10 12 12 10
                                        5 0 0 0 0 0
                                        5 12 0 0 0 0
                                        5 12 10 0 0 0
                                        5 12 10 12 0 0
                                        5 12 10 12 12 0
                                        5 12 10 12 12 10

                                        ]= is each number from the input equal to the prefix:
                                        (]=]) 5 12 10 12 12 10
                                        1 0 0 0 0 0
                                        0 1 0 0 0 0
                                        0 0 1 0 0 0
                                        0 1 0 1 0 0
                                        0 1 0 1 1 0
                                        0 0 1 0 0 1

                                        1#. sum each row:
                                        (1#.]=]) 5 12 10 12 12 10
                                        1 1 1 2 3 2



                                        K (oK), 11 bytes



                                        {+/'x=',x}


                                        Try it online!






                                        share|improve this answer















                                        J, 7 bytes



                                        1#.]=]


                                        Try it online!



                                        1-indexed.



                                        Explanation:



                                        ] all the prefixes (filled with zeros, but there won't be any 0s in the input):
                                        ] 5 12 10 12 12 10
                                        5 0 0 0 0 0
                                        5 12 0 0 0 0
                                        5 12 10 0 0 0
                                        5 12 10 12 0 0
                                        5 12 10 12 12 0
                                        5 12 10 12 12 10

                                        ]= is each number from the input equal to the prefix:
                                        (]=]) 5 12 10 12 12 10
                                        1 0 0 0 0 0
                                        0 1 0 0 0 0
                                        0 0 1 0 0 0
                                        0 1 0 1 0 0
                                        0 1 0 1 1 0
                                        0 0 1 0 0 1

                                        1#. sum each row:
                                        (1#.]=]) 5 12 10 12 12 10
                                        1 1 1 2 3 2



                                        K (oK), 11 bytes



                                        {+/'x=',x}


                                        Try it online!







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited 20 hours ago

























                                        answered yesterday









                                        Galen IvanovGalen Ivanov

                                        6,43711032




                                        6,43711032








                                        • 1




                                          Heh, you're happy that I made the data strictly positive…
                                          – Adám
                                          yesterday










                                        • @Adám Yes, otherwise I'd need to box the prefixes :)
                                          – Galen Ivanov
                                          yesterday














                                        • 1




                                          Heh, you're happy that I made the data strictly positive…
                                          – Adám
                                          yesterday










                                        • @Adám Yes, otherwise I'd need to box the prefixes :)
                                          – Galen Ivanov
                                          yesterday








                                        1




                                        1




                                        Heh, you're happy that I made the data strictly positive…
                                        – Adám
                                        yesterday




                                        Heh, you're happy that I made the data strictly positive…
                                        – Adám
                                        yesterday












                                        @Adám Yes, otherwise I'd need to box the prefixes :)
                                        – Galen Ivanov
                                        yesterday




                                        @Adám Yes, otherwise I'd need to box the prefixes :)
                                        – Galen Ivanov
                                        yesterday











                                        4















                                        Python 2, 48 bytes





                                        lambda a:[a[:i].count(v)for i,v in enumerate(a)]


                                        Try it online!






                                        share|improve this answer


























                                          4















                                          Python 2, 48 bytes





                                          lambda a:[a[:i].count(v)for i,v in enumerate(a)]


                                          Try it online!






                                          share|improve this answer
























                                            4












                                            4








                                            4







                                            Python 2, 48 bytes





                                            lambda a:[a[:i].count(v)for i,v in enumerate(a)]


                                            Try it online!






                                            share|improve this answer













                                            Python 2, 48 bytes





                                            lambda a:[a[:i].count(v)for i,v in enumerate(a)]


                                            Try it online!







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered yesterday









                                            TFeldTFeld

                                            14.4k21240




                                            14.4k21240























                                                3















                                                05AB1E, 4 bytes



                                                ηε¤¢


                                                Try it online!
                                                or as a Test Suite



                                                Explanation



                                                ηε     # apply to each prefix of the input list
                                                ¤¢ # count occurrences of the last element





                                                share|improve this answer


























                                                  3















                                                  05AB1E, 4 bytes



                                                  ηε¤¢


                                                  Try it online!
                                                  or as a Test Suite



                                                  Explanation



                                                  ηε     # apply to each prefix of the input list
                                                  ¤¢ # count occurrences of the last element





                                                  share|improve this answer
























                                                    3












                                                    3








                                                    3







                                                    05AB1E, 4 bytes



                                                    ηε¤¢


                                                    Try it online!
                                                    or as a Test Suite



                                                    Explanation



                                                    ηε     # apply to each prefix of the input list
                                                    ¤¢ # count occurrences of the last element





                                                    share|improve this answer













                                                    05AB1E, 4 bytes



                                                    ηε¤¢


                                                    Try it online!
                                                    or as a Test Suite



                                                    Explanation



                                                    ηε     # apply to each prefix of the input list
                                                    ¤¢ # count occurrences of the last element






                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered yesterday









                                                    EmignaEmigna

                                                    45.5k432138




                                                    45.5k432138























                                                        3















                                                        AWK, 15



                                                        {print a[$1]++}


                                                        Try it online!



                                                        The above does zero-based indexing. If you prefer one-based indexing, its a simple change:



                                                        {print ++a[$1]}


                                                        Try it online!






                                                        share|improve this answer




























                                                          3















                                                          AWK, 15



                                                          {print a[$1]++}


                                                          Try it online!



                                                          The above does zero-based indexing. If you prefer one-based indexing, its a simple change:



                                                          {print ++a[$1]}


                                                          Try it online!






                                                          share|improve this answer


























                                                            3












                                                            3








                                                            3







                                                            AWK, 15



                                                            {print a[$1]++}


                                                            Try it online!



                                                            The above does zero-based indexing. If you prefer one-based indexing, its a simple change:



                                                            {print ++a[$1]}


                                                            Try it online!






                                                            share|improve this answer















                                                            AWK, 15



                                                            {print a[$1]++}


                                                            Try it online!



                                                            The above does zero-based indexing. If you prefer one-based indexing, its a simple change:



                                                            {print ++a[$1]}


                                                            Try it online!







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited yesterday

























                                                            answered yesterday









                                                            Digital TraumaDigital Trauma

                                                            58.6k787221




                                                            58.6k787221























                                                                2















                                                                Python 2, 47 43 bytes





                                                                f=lambda a:a and f(a[:-1])+[a.count(a[-1])]


                                                                Try it online!



                                                                A recursive 'one-based' solution.






                                                                share|improve this answer




























                                                                  2















                                                                  Python 2, 47 43 bytes





                                                                  f=lambda a:a and f(a[:-1])+[a.count(a[-1])]


                                                                  Try it online!



                                                                  A recursive 'one-based' solution.






                                                                  share|improve this answer


























                                                                    2












                                                                    2








                                                                    2







                                                                    Python 2, 47 43 bytes





                                                                    f=lambda a:a and f(a[:-1])+[a.count(a[-1])]


                                                                    Try it online!



                                                                    A recursive 'one-based' solution.






                                                                    share|improve this answer















                                                                    Python 2, 47 43 bytes





                                                                    f=lambda a:a and f(a[:-1])+[a.count(a[-1])]


                                                                    Try it online!



                                                                    A recursive 'one-based' solution.







                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited yesterday

























                                                                    answered yesterday









                                                                    Chas BrownChas Brown

                                                                    4,8391522




                                                                    4,8391522























                                                                        2















                                                                        Jelly, 4 bytes



                                                                        ċṪ$Ƥ


                                                                        Try it online!



                                                                        For each prefix of the input list, it counts the number of occurrences of its last element in itself.






                                                                        share|improve this answer





















                                                                        • Alternatively the old-school ;ċ" is also 4.
                                                                          – Jonathan Allan
                                                                          yesterday
















                                                                        2















                                                                        Jelly, 4 bytes



                                                                        ċṪ$Ƥ


                                                                        Try it online!



                                                                        For each prefix of the input list, it counts the number of occurrences of its last element in itself.






                                                                        share|improve this answer





















                                                                        • Alternatively the old-school ;ċ" is also 4.
                                                                          – Jonathan Allan
                                                                          yesterday














                                                                        2












                                                                        2








                                                                        2







                                                                        Jelly, 4 bytes



                                                                        ċṪ$Ƥ


                                                                        Try it online!



                                                                        For each prefix of the input list, it counts the number of occurrences of its last element in itself.






                                                                        share|improve this answer













                                                                        Jelly, 4 bytes



                                                                        ċṪ$Ƥ


                                                                        Try it online!



                                                                        For each prefix of the input list, it counts the number of occurrences of its last element in itself.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered yesterday









                                                                        Mr. XcoderMr. Xcoder

                                                                        31.7k759198




                                                                        31.7k759198












                                                                        • Alternatively the old-school ;ċ" is also 4.
                                                                          – Jonathan Allan
                                                                          yesterday


















                                                                        • Alternatively the old-school ;ċ" is also 4.
                                                                          – Jonathan Allan
                                                                          yesterday
















                                                                        Alternatively the old-school ;ċ" is also 4.
                                                                        – Jonathan Allan
                                                                        yesterday




                                                                        Alternatively the old-school ;ċ" is also 4.
                                                                        – Jonathan Allan
                                                                        yesterday











                                                                        2















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





                                                                        x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))


                                                                        Try it online!






                                                                        share|improve this answer























                                                                        • 22 bytes
                                                                          – LiefdeWen
                                                                          yesterday










                                                                        • You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                          – Kevin Cruijssen
                                                                          yesterday






                                                                        • 1




                                                                          @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                          – dana
                                                                          yesterday
















                                                                        2















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





                                                                        x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))


                                                                        Try it online!






                                                                        share|improve this answer























                                                                        • 22 bytes
                                                                          – LiefdeWen
                                                                          yesterday










                                                                        • You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                          – Kevin Cruijssen
                                                                          yesterday






                                                                        • 1




                                                                          @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                          – dana
                                                                          yesterday














                                                                        2












                                                                        2








                                                                        2







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





                                                                        x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))


                                                                        Try it online!






                                                                        share|improve this answer















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





                                                                        x=>x.Select((y,i)=>x.Take(i).Count(z=>z==y))


                                                                        Try it online!







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited yesterday

























                                                                        answered yesterday









                                                                        danadana

                                                                        55135




                                                                        55135












                                                                        • 22 bytes
                                                                          – LiefdeWen
                                                                          yesterday










                                                                        • You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                          – Kevin Cruijssen
                                                                          yesterday






                                                                        • 1




                                                                          @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                          – dana
                                                                          yesterday


















                                                                        • 22 bytes
                                                                          – LiefdeWen
                                                                          yesterday










                                                                        • You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                          – Kevin Cruijssen
                                                                          yesterday






                                                                        • 1




                                                                          @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                          – dana
                                                                          yesterday
















                                                                        22 bytes
                                                                        – LiefdeWen
                                                                        yesterday




                                                                        22 bytes
                                                                        – LiefdeWen
                                                                        yesterday












                                                                        You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                        – Kevin Cruijssen
                                                                        yesterday




                                                                        You have the inversed of the challenge right now.. [7,7,7] should output [0,1,2], and not [0,0,0].
                                                                        – Kevin Cruijssen
                                                                        yesterday




                                                                        1




                                                                        1




                                                                        @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                        – dana
                                                                        yesterday




                                                                        @KevinCruijssen - Thanks :) Looks like I misread things, it should be fixed now.
                                                                        – dana
                                                                        yesterday











                                                                        2














                                                                        Ruby, 35 bytes



                                                                        ->a{f=Hash.new 0;a.map{|v|f[v]+=1}}


                                                                        It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.



                                                                        Some other, fun options that unfortunately weren't quite short enough:



                                                                        ->a{a.dup.map{a.count a.pop}.reverse}   # 37
                                                                        ->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38





                                                                        share|improve this answer


























                                                                          2














                                                                          Ruby, 35 bytes



                                                                          ->a{f=Hash.new 0;a.map{|v|f[v]+=1}}


                                                                          It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.



                                                                          Some other, fun options that unfortunately weren't quite short enough:



                                                                          ->a{a.dup.map{a.count a.pop}.reverse}   # 37
                                                                          ->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38





                                                                          share|improve this answer
























                                                                            2












                                                                            2








                                                                            2






                                                                            Ruby, 35 bytes



                                                                            ->a{f=Hash.new 0;a.map{|v|f[v]+=1}}


                                                                            It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.



                                                                            Some other, fun options that unfortunately weren't quite short enough:



                                                                            ->a{a.dup.map{a.count a.pop}.reverse}   # 37
                                                                            ->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38





                                                                            share|improve this answer












                                                                            Ruby, 35 bytes



                                                                            ->a{f=Hash.new 0;a.map{|v|f[v]+=1}}


                                                                            It's pretty mundane, unfortunately - build a hash that stores the total for each entry encountered so far.



                                                                            Some other, fun options that unfortunately weren't quite short enough:



                                                                            ->a{a.dup.map{a.count a.pop}.reverse}   # 37
                                                                            ->a{i=-1;a.map{|v|a[0..i+=1].count v}} # 38






                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered yesterday









                                                                            DaveMongooseDaveMongoose

                                                                            1414




                                                                            1414























                                                                                2















                                                                                Perl 6, 15 bytes





                                                                                *>>.&{%.{$_}++}


                                                                                Try it online!



                                                                                You can move the ++ to before the % for a one based index.



                                                                                Explanation:



                                                                                *>>.&{        }  # Map the input to
                                                                                % # An anonymous hash
                                                                                .{$_} # The current element indexed
                                                                                ++ # Incremented





                                                                                share|improve this answer




























                                                                                  2















                                                                                  Perl 6, 15 bytes





                                                                                  *>>.&{%.{$_}++}


                                                                                  Try it online!



                                                                                  You can move the ++ to before the % for a one based index.



                                                                                  Explanation:



                                                                                  *>>.&{        }  # Map the input to
                                                                                  % # An anonymous hash
                                                                                  .{$_} # The current element indexed
                                                                                  ++ # Incremented





                                                                                  share|improve this answer


























                                                                                    2












                                                                                    2








                                                                                    2







                                                                                    Perl 6, 15 bytes





                                                                                    *>>.&{%.{$_}++}


                                                                                    Try it online!



                                                                                    You can move the ++ to before the % for a one based index.



                                                                                    Explanation:



                                                                                    *>>.&{        }  # Map the input to
                                                                                    % # An anonymous hash
                                                                                    .{$_} # The current element indexed
                                                                                    ++ # Incremented





                                                                                    share|improve this answer















                                                                                    Perl 6, 15 bytes





                                                                                    *>>.&{%.{$_}++}


                                                                                    Try it online!



                                                                                    You can move the ++ to before the % for a one based index.



                                                                                    Explanation:



                                                                                    *>>.&{        }  # Map the input to
                                                                                    % # An anonymous hash
                                                                                    .{$_} # The current element indexed
                                                                                    ++ # Incremented






                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited 19 hours ago

























                                                                                    answered yesterday









                                                                                    Jo KingJo King

                                                                                    21.1k248110




                                                                                    21.1k248110























                                                                                        1















                                                                                        R, 41 bytes





                                                                                        function(x)diag(diffinv(outer(x,x,"==")))


                                                                                        Try it online!



                                                                                        Oddly, returning a zero-based index is shorter in R.






                                                                                        share|improve this answer





















                                                                                        • Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                          – Sumner18
                                                                                          yesterday










                                                                                        • @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                          – Giuseppe
                                                                                          yesterday












                                                                                        • thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                          – Sumner18
                                                                                          yesterday
















                                                                                        1















                                                                                        R, 41 bytes





                                                                                        function(x)diag(diffinv(outer(x,x,"==")))


                                                                                        Try it online!



                                                                                        Oddly, returning a zero-based index is shorter in R.






                                                                                        share|improve this answer





















                                                                                        • Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                          – Sumner18
                                                                                          yesterday










                                                                                        • @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                          – Giuseppe
                                                                                          yesterday












                                                                                        • thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                          – Sumner18
                                                                                          yesterday














                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        R, 41 bytes





                                                                                        function(x)diag(diffinv(outer(x,x,"==")))


                                                                                        Try it online!



                                                                                        Oddly, returning a zero-based index is shorter in R.






                                                                                        share|improve this answer













                                                                                        R, 41 bytes





                                                                                        function(x)diag(diffinv(outer(x,x,"==")))


                                                                                        Try it online!



                                                                                        Oddly, returning a zero-based index is shorter in R.







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered yesterday









                                                                                        GiuseppeGiuseppe

                                                                                        16.6k31052




                                                                                        16.6k31052












                                                                                        • Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                          – Sumner18
                                                                                          yesterday










                                                                                        • @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                          – Giuseppe
                                                                                          yesterday












                                                                                        • thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                          – Sumner18
                                                                                          yesterday


















                                                                                        • Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                          – Sumner18
                                                                                          yesterday










                                                                                        • @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                          – Giuseppe
                                                                                          yesterday












                                                                                        • thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                          – Sumner18
                                                                                          yesterday
















                                                                                        Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                        – Sumner18
                                                                                        yesterday




                                                                                        Once again Giuseppe, your superior knowledge of R has beaten me. I had a decently ingenious method at 60 bytes, but alas, it wasn't enough!
                                                                                        – Sumner18
                                                                                        yesterday












                                                                                        @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                        – Giuseppe
                                                                                        yesterday






                                                                                        @Sumner18 post it anyway! I always learn a lot from other peoples' approaches, and getting feedback is the fastest way to learn!
                                                                                        – Giuseppe
                                                                                        yesterday














                                                                                        thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                        – Sumner18
                                                                                        yesterday




                                                                                        thanks for the encouragement! I've posted mine now and am always open to suggestions for improvement!
                                                                                        – Sumner18
                                                                                        yesterday











                                                                                        1















                                                                                        Java (JDK), 76 bytes





                                                                                        a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}


                                                                                        Try it online!



                                                                                        Credits




                                                                                        • -2 bytes thanks to Kevin Cruijssen






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                          – Kevin Cruijssen
                                                                                          yesterday
















                                                                                        1















                                                                                        Java (JDK), 76 bytes





                                                                                        a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}


                                                                                        Try it online!



                                                                                        Credits




                                                                                        • -2 bytes thanks to Kevin Cruijssen






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                          – Kevin Cruijssen
                                                                                          yesterday














                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        Java (JDK), 76 bytes





                                                                                        a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}


                                                                                        Try it online!



                                                                                        Credits




                                                                                        • -2 bytes thanks to Kevin Cruijssen






                                                                                        share|improve this answer















                                                                                        Java (JDK), 76 bytes





                                                                                        a->{for(int l=a.length,i,c;l-->0;a[l]=c)for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;}


                                                                                        Try it online!



                                                                                        Credits




                                                                                        • -2 bytes thanks to Kevin Cruijssen







                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited yesterday

























                                                                                        answered yesterday









                                                                                        Olivier GrégoireOlivier Grégoire

                                                                                        8,83711843




                                                                                        8,83711843








                                                                                        • 1




                                                                                          -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                          – Kevin Cruijssen
                                                                                          yesterday














                                                                                        • 1




                                                                                          -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                          – Kevin Cruijssen
                                                                                          yesterday








                                                                                        1




                                                                                        1




                                                                                        -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                        – Kevin Cruijssen
                                                                                        yesterday




                                                                                        -2 bytes by changing for(c=0,i=l;i-->0;)c+=a[l]==a[i]?1:0; to for(c=i=0;i<l;)c+=a[l]==a[i++]?1:0;.
                                                                                        – Kevin Cruijssen
                                                                                        yesterday











                                                                                        1















                                                                                        R, 62 43 bytes





                                                                                        x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z


                                                                                        -19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation



                                                                                        Original



                                                                                        x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z


                                                                                        I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.



                                                                                        r<-table(x) counts the number of times each number appears and stores it in r, for future reference



                                                                                        names() gets the values of each unique entry in the table, and we iterate over these names with a for loop.



                                                                                        The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)



                                                                                        Try it online!






                                                                                        share|improve this answer























                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          yesterday










                                                                                        • Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                          – Giuseppe
                                                                                          yesterday


















                                                                                        1















                                                                                        R, 62 43 bytes





                                                                                        x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z


                                                                                        -19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation



                                                                                        Original



                                                                                        x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z


                                                                                        I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.



                                                                                        r<-table(x) counts the number of times each number appears and stores it in r, for future reference



                                                                                        names() gets the values of each unique entry in the table, and we iterate over these names with a for loop.



                                                                                        The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)



                                                                                        Try it online!






                                                                                        share|improve this answer























                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          yesterday










                                                                                        • Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                          – Giuseppe
                                                                                          yesterday
















                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        R, 62 43 bytes





                                                                                        x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z


                                                                                        -19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation



                                                                                        Original



                                                                                        x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z


                                                                                        I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.



                                                                                        r<-table(x) counts the number of times each number appears and stores it in r, for future reference



                                                                                        names() gets the values of each unique entry in the table, and we iterate over these names with a for loop.



                                                                                        The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)



                                                                                        Try it online!






                                                                                        share|improve this answer















                                                                                        R, 62 43 bytes





                                                                                        x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z


                                                                                        -19 bytes thanks to Giuseppe, by removing which, and table, and only slight changes to the implementation



                                                                                        Original



                                                                                        x=z=scan();for(i in names(r<-table(x)))z[which(x==i)]=1:r[i];z


                                                                                        I can't compete with Giuseppe's knowledge, so my submission is somewhat longer than his, but using my basic knowledge, I felt that this solution was rather ingenious.



                                                                                        r<-table(x) counts the number of times each number appears and stores it in r, for future reference



                                                                                        names() gets the values of each unique entry in the table, and we iterate over these names with a for loop.



                                                                                        The remaining portion checks which entries are equal to the iterations and stores a sequence of values (from 1 to the number of entries of the iteration)



                                                                                        Try it online!







                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited yesterday

























                                                                                        answered yesterday









                                                                                        Sumner18Sumner18

                                                                                        4007




                                                                                        4007












                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          yesterday










                                                                                        • Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                          – Giuseppe
                                                                                          yesterday




















                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          yesterday










                                                                                        • Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                          – Giuseppe
                                                                                          yesterday


















                                                                                        you can remove the which() to save 7 bytes.
                                                                                        – Giuseppe
                                                                                        yesterday




                                                                                        you can remove the which() to save 7 bytes.
                                                                                        – Giuseppe
                                                                                        yesterday












                                                                                        Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                        – Giuseppe
                                                                                        yesterday






                                                                                        Your use of 1:r[i] gave me the idea to just remove table() entirely: x=z=scan();for(i in x)z[y]=1:sum(y<-x==i);z is 43 bytes! This is a nice approach!
                                                                                        – Giuseppe
                                                                                        yesterday













                                                                                        1















                                                                                        Ruby, 34 bytes





                                                                                        ->a{r=;a.map{|x|(r<<x).count x}}


                                                                                        Try it online!






                                                                                        share|improve this answer





















                                                                                        • I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                          – DaveMongoose
                                                                                          19 hours ago


















                                                                                        1















                                                                                        Ruby, 34 bytes





                                                                                        ->a{r=;a.map{|x|(r<<x).count x}}


                                                                                        Try it online!






                                                                                        share|improve this answer





















                                                                                        • I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                          – DaveMongoose
                                                                                          19 hours ago
















                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        Ruby, 34 bytes





                                                                                        ->a{r=;a.map{|x|(r<<x).count x}}


                                                                                        Try it online!






                                                                                        share|improve this answer













                                                                                        Ruby, 34 bytes





                                                                                        ->a{r=;a.map{|x|(r<<x).count x}}


                                                                                        Try it online!







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered yesterday









                                                                                        G BG B

                                                                                        7,6961328




                                                                                        7,6961328












                                                                                        • I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                          – DaveMongoose
                                                                                          19 hours ago




















                                                                                        • I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                          – DaveMongoose
                                                                                          19 hours ago


















                                                                                        I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                        – DaveMongoose
                                                                                        19 hours ago






                                                                                        I can't believe I tried ->a{i=-1;a.map{|v|a[0..i+=1].count v}} and didn't think of just building a new array, lol. Nice work.
                                                                                        – DaveMongoose
                                                                                        19 hours ago













                                                                                        1














                                                                                        bash, 37 bytes or 24 bytes



                                                                                        f()(for x;{ r+=$[a[x]++] ;};echo $r)


                                                                                        TIO



                                                                                        if valid, there is also this variation, as suggested by DigitalTrauma



                                                                                        for x;{ echo $[a[x]++];}


                                                                                        TIO






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          yesterday










                                                                                        • @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                          – Nahuel Fouilleul
                                                                                          21 hours ago






                                                                                        • 1




                                                                                          @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                          – ASCII-only
                                                                                          21 hours ago
















                                                                                        1














                                                                                        bash, 37 bytes or 24 bytes



                                                                                        f()(for x;{ r+=$[a[x]++] ;};echo $r)


                                                                                        TIO



                                                                                        if valid, there is also this variation, as suggested by DigitalTrauma



                                                                                        for x;{ echo $[a[x]++];}


                                                                                        TIO






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          yesterday










                                                                                        • @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                          – Nahuel Fouilleul
                                                                                          21 hours ago






                                                                                        • 1




                                                                                          @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                          – ASCII-only
                                                                                          21 hours ago














                                                                                        1












                                                                                        1








                                                                                        1






                                                                                        bash, 37 bytes or 24 bytes



                                                                                        f()(for x;{ r+=$[a[x]++] ;};echo $r)


                                                                                        TIO



                                                                                        if valid, there is also this variation, as suggested by DigitalTrauma



                                                                                        for x;{ echo $[a[x]++];}


                                                                                        TIO






                                                                                        share|improve this answer














                                                                                        bash, 37 bytes or 24 bytes



                                                                                        f()(for x;{ r+=$[a[x]++] ;};echo $r)


                                                                                        TIO



                                                                                        if valid, there is also this variation, as suggested by DigitalTrauma



                                                                                        for x;{ echo $[a[x]++];}


                                                                                        TIO







                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited 21 hours ago

























                                                                                        answered yesterday









                                                                                        Nahuel FouilleulNahuel Fouilleul

                                                                                        1,61228




                                                                                        1,61228








                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          yesterday










                                                                                        • @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                          – Nahuel Fouilleul
                                                                                          21 hours ago






                                                                                        • 1




                                                                                          @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                          – ASCII-only
                                                                                          21 hours ago














                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          yesterday










                                                                                        • @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                          – Nahuel Fouilleul
                                                                                          21 hours ago






                                                                                        • 1




                                                                                          @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                          – ASCII-only
                                                                                          21 hours ago








                                                                                        1




                                                                                        1




                                                                                        Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                        – Digital Trauma
                                                                                        yesterday




                                                                                        Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                        – Digital Trauma
                                                                                        yesterday












                                                                                        @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                        – Nahuel Fouilleul
                                                                                        21 hours ago




                                                                                        @DigitalTrauma, thanks however i don't know if it broke the rules. also as it was asked to replace list and maybe should be something like tio.run/…
                                                                                        – Nahuel Fouilleul
                                                                                        21 hours ago




                                                                                        1




                                                                                        1




                                                                                        @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                        – ASCII-only
                                                                                        21 hours ago




                                                                                        @NahuelFouilleul It's fine, full programs are allowed too, and that's a valid method of inputting/outputting a list (IMO)
                                                                                        – ASCII-only
                                                                                        21 hours ago











                                                                                        0















                                                                                        Retina 0.8.2, 30 bytes



                                                                                        b(d+)b(?<=(b1b.*?)+)
                                                                                        $#2


                                                                                        Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.






                                                                                        share|improve this answer


























                                                                                          0















                                                                                          Retina 0.8.2, 30 bytes



                                                                                          b(d+)b(?<=(b1b.*?)+)
                                                                                          $#2


                                                                                          Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.






                                                                                          share|improve this answer
























                                                                                            0












                                                                                            0








                                                                                            0







                                                                                            Retina 0.8.2, 30 bytes



                                                                                            b(d+)b(?<=(b1b.*?)+)
                                                                                            $#2


                                                                                            Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.






                                                                                            share|improve this answer













                                                                                            Retina 0.8.2, 30 bytes



                                                                                            b(d+)b(?<=(b1b.*?)+)
                                                                                            $#2


                                                                                            Try it online! Link includes test cases. 1-indexed. Explanation: The first part of the regex matches each integer in the list in turn. The lookbehind's group matches each occurrence of that integer on that line up to and including the current integer. The integer is then substituted with the number of matches.







                                                                                            share|improve this answer












                                                                                            share|improve this answer



                                                                                            share|improve this answer










                                                                                            answered yesterday









                                                                                            NeilNeil

                                                                                            79.6k744177




                                                                                            79.6k744177























                                                                                                0














                                                                                                Batch, 61 bytes



                                                                                                @setlocal
                                                                                                @for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%


                                                                                                1-indexed. Because variable substitution happens before parsing, the set/a command ends up incrementing the variable name given by concatenating the letter c with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).






                                                                                                share|improve this answer


























                                                                                                  0














                                                                                                  Batch, 61 bytes



                                                                                                  @setlocal
                                                                                                  @for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%


                                                                                                  1-indexed. Because variable substitution happens before parsing, the set/a command ends up incrementing the variable name given by concatenating the letter c with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).






                                                                                                  share|improve this answer
























                                                                                                    0












                                                                                                    0








                                                                                                    0






                                                                                                    Batch, 61 bytes



                                                                                                    @setlocal
                                                                                                    @for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%


                                                                                                    1-indexed. Because variable substitution happens before parsing, the set/a command ends up incrementing the variable name given by concatenating the letter c with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).






                                                                                                    share|improve this answer












                                                                                                    Batch, 61 bytes



                                                                                                    @setlocal
                                                                                                    @for %%n in (%*)do @set/ac=c%%n+=1&call echo %%c%%


                                                                                                    1-indexed. Because variable substitution happens before parsing, the set/a command ends up incrementing the variable name given by concatenating the letter c with the integer from the list (numeric variables default to zero in Batch). The result is then copied to another integer for ease of output (more precisely, it saves a byte).







                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered yesterday









                                                                                                    NeilNeil

                                                                                                    79.6k744177




                                                                                                    79.6k744177























                                                                                                        0














                                                                                                        awk (46 bytes)



                                                                                                        {delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}


                                                                                                        TIO






                                                                                                        share|improve this answer


























                                                                                                          0














                                                                                                          awk (46 bytes)



                                                                                                          {delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}


                                                                                                          TIO






                                                                                                          share|improve this answer
























                                                                                                            0












                                                                                                            0








                                                                                                            0






                                                                                                            awk (46 bytes)



                                                                                                            {delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}


                                                                                                            TIO






                                                                                                            share|improve this answer












                                                                                                            awk (46 bytes)



                                                                                                            {delete(a);for(i=1;i<=NF;i++)$i=a[$i]++;print}


                                                                                                            TIO







                                                                                                            share|improve this answer












                                                                                                            share|improve this answer



                                                                                                            share|improve this answer










                                                                                                            answered yesterday









                                                                                                            Nahuel FouilleulNahuel Fouilleul

                                                                                                            1,61228




                                                                                                            1,61228























                                                                                                                0















                                                                                                                Tcl, 48 bytes



                                                                                                                proc C L {lmap n $L {dict g [dict inc D $n] $n}}


                                                                                                                Try it online!






                                                                                                                share|improve this answer




























                                                                                                                  0















                                                                                                                  Tcl, 48 bytes



                                                                                                                  proc C L {lmap n $L {dict g [dict inc D $n] $n}}


                                                                                                                  Try it online!






                                                                                                                  share|improve this answer


























                                                                                                                    0












                                                                                                                    0








                                                                                                                    0







                                                                                                                    Tcl, 48 bytes



                                                                                                                    proc C L {lmap n $L {dict g [dict inc D $n] $n}}


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer















                                                                                                                    Tcl, 48 bytes



                                                                                                                    proc C L {lmap n $L {dict g [dict inc D $n] $n}}


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited yesterday

























                                                                                                                    answered yesterday









                                                                                                                    sergiolsergiol

                                                                                                                    2,5121925




                                                                                                                    2,5121925























                                                                                                                        0














                                                                                                                        Japt, 8 bytes



                                                                                                                        £¯YÄ è¶X


                                                                                                                        Try it here



                                                                                                                        £¯YÄ è¶X
                                                                                                                        :Implicit input of array U
                                                                                                                        £ :Map each X at 0-based index Y
                                                                                                                        ¯ : Slice U to index
                                                                                                                        YÄ : Y+1
                                                                                                                        è : Count the elements
                                                                                                                        ¶X : Equal to X





                                                                                                                        share|improve this answer




























                                                                                                                          0














                                                                                                                          Japt, 8 bytes



                                                                                                                          £¯YÄ è¶X


                                                                                                                          Try it here



                                                                                                                          £¯YÄ è¶X
                                                                                                                          :Implicit input of array U
                                                                                                                          £ :Map each X at 0-based index Y
                                                                                                                          ¯ : Slice U to index
                                                                                                                          YÄ : Y+1
                                                                                                                          è : Count the elements
                                                                                                                          ¶X : Equal to X





                                                                                                                          share|improve this answer


























                                                                                                                            0












                                                                                                                            0








                                                                                                                            0






                                                                                                                            Japt, 8 bytes



                                                                                                                            £¯YÄ è¶X


                                                                                                                            Try it here



                                                                                                                            £¯YÄ è¶X
                                                                                                                            :Implicit input of array U
                                                                                                                            £ :Map each X at 0-based index Y
                                                                                                                            ¯ : Slice U to index
                                                                                                                            YÄ : Y+1
                                                                                                                            è : Count the elements
                                                                                                                            ¶X : Equal to X





                                                                                                                            share|improve this answer














                                                                                                                            Japt, 8 bytes



                                                                                                                            £¯YÄ è¶X


                                                                                                                            Try it here



                                                                                                                            £¯YÄ è¶X
                                                                                                                            :Implicit input of array U
                                                                                                                            £ :Map each X at 0-based index Y
                                                                                                                            ¯ : Slice U to index
                                                                                                                            YÄ : Y+1
                                                                                                                            è : Count the elements
                                                                                                                            ¶X : Equal to X






                                                                                                                            share|improve this answer














                                                                                                                            share|improve this answer



                                                                                                                            share|improve this answer








                                                                                                                            edited yesterday

























                                                                                                                            answered yesterday









                                                                                                                            ShaggyShaggy

                                                                                                                            19.2k21666




                                                                                                                            19.2k21666























                                                                                                                                0















                                                                                                                                Haskell, 44 bytes





                                                                                                                                (#)
                                                                                                                                x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
                                                                                                                                _#e=e


                                                                                                                                Try it online!



                                                                                                                                Explanation



                                                                                                                                Traverses the list from left to right keeping the list x of visited elements, initially :



                                                                                                                                For every encounter of a y count all equal elements in the list x.






                                                                                                                                share|improve this answer


























                                                                                                                                  0















                                                                                                                                  Haskell, 44 bytes





                                                                                                                                  (#)
                                                                                                                                  x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
                                                                                                                                  _#e=e


                                                                                                                                  Try it online!



                                                                                                                                  Explanation



                                                                                                                                  Traverses the list from left to right keeping the list x of visited elements, initially :



                                                                                                                                  For every encounter of a y count all equal elements in the list x.






                                                                                                                                  share|improve this answer
























                                                                                                                                    0












                                                                                                                                    0








                                                                                                                                    0







                                                                                                                                    Haskell, 44 bytes





                                                                                                                                    (#)
                                                                                                                                    x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
                                                                                                                                    _#e=e


                                                                                                                                    Try it online!



                                                                                                                                    Explanation



                                                                                                                                    Traverses the list from left to right keeping the list x of visited elements, initially :



                                                                                                                                    For every encounter of a y count all equal elements in the list x.






                                                                                                                                    share|improve this answer













                                                                                                                                    Haskell, 44 bytes





                                                                                                                                    (#)
                                                                                                                                    x#(y:z)=sum[1|a<-x,a==y]:(y:x)#z
                                                                                                                                    _#e=e


                                                                                                                                    Try it online!



                                                                                                                                    Explanation



                                                                                                                                    Traverses the list from left to right keeping the list x of visited elements, initially :



                                                                                                                                    For every encounter of a y count all equal elements in the list x.







                                                                                                                                    share|improve this answer












                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer










                                                                                                                                    answered yesterday









                                                                                                                                    BMOBMO

                                                                                                                                    11.7k22188




                                                                                                                                    11.7k22188























                                                                                                                                        0














                                                                                                                                        Haxe, 58 bytes



                                                                                                                                        l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};


                                                                                                                                        (Requires arrow functions, so 4.0+)



                                                                                                                                        var x=[0=>0] declares a new IntMap, with 0 as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null to a number, hence the explicit check to make sure each key is in the map before incrementing.



                                                                                                                                        Also a cheeky rip off based on the JS answer:



                                                                                                                                        Haxe (JS target), 41 bytes



                                                                                                                                        l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};


                                                                                                                                        Try both online






                                                                                                                                        share|improve this answer


























                                                                                                                                          0














                                                                                                                                          Haxe, 58 bytes



                                                                                                                                          l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};


                                                                                                                                          (Requires arrow functions, so 4.0+)



                                                                                                                                          var x=[0=>0] declares a new IntMap, with 0 as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null to a number, hence the explicit check to make sure each key is in the map before incrementing.



                                                                                                                                          Also a cheeky rip off based on the JS answer:



                                                                                                                                          Haxe (JS target), 41 bytes



                                                                                                                                          l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};


                                                                                                                                          Try both online






                                                                                                                                          share|improve this answer
























                                                                                                                                            0












                                                                                                                                            0








                                                                                                                                            0






                                                                                                                                            Haxe, 58 bytes



                                                                                                                                            l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};


                                                                                                                                            (Requires arrow functions, so 4.0+)



                                                                                                                                            var x=[0=>0] declares a new IntMap, with 0 as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null to a number, hence the explicit check to make sure each key is in the map before incrementing.



                                                                                                                                            Also a cheeky rip off based on the JS answer:



                                                                                                                                            Haxe (JS target), 41 bytes



                                                                                                                                            l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};


                                                                                                                                            Try both online






                                                                                                                                            share|improve this answer












                                                                                                                                            Haxe, 58 bytes



                                                                                                                                            l->{var x=[0=>0];l.map(e->++x[(x[e]==null?x[e]=0:0)+e]);};


                                                                                                                                            (Requires arrow functions, so 4.0+)



                                                                                                                                            var x=[0=>0] declares a new IntMap, with 0 as its only key (since the question say inputs are strictly positive). Unfortunately most targets throw when adding null to a number, hence the explicit check to make sure each key is in the map before incrementing.



                                                                                                                                            Also a cheeky rip off based on the JS answer:



                                                                                                                                            Haxe (JS target), 41 bytes



                                                                                                                                            l->{var x=[0=>0];l.map(e->x[e]=-~x[e]);};


                                                                                                                                            Try both online







                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered yesterday









                                                                                                                                            Aurel BílýAurel Bílý

                                                                                                                                            1,07398




                                                                                                                                            1,07398























                                                                                                                                                0














                                                                                                                                                GO 121 Bytes (Not included new lines and tabs)



                                                                                                                                                func cg(a int) int{
                                                                                                                                                var m = make(map[int]int)
                                                                                                                                                var r = make(int, len(a))
                                                                                                                                                for i,v := range a{
                                                                                                                                                r[i] = m[v]
                                                                                                                                                m[v]++
                                                                                                                                                }
                                                                                                                                                return r
                                                                                                                                                }


                                                                                                                                                Accepts integer array and returns integer array.






                                                                                                                                                share|improve this answer








                                                                                                                                                New contributor




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














                                                                                                                                                • 3




                                                                                                                                                  Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                  – Adám
                                                                                                                                                  19 hours ago
















                                                                                                                                                0














                                                                                                                                                GO 121 Bytes (Not included new lines and tabs)



                                                                                                                                                func cg(a int) int{
                                                                                                                                                var m = make(map[int]int)
                                                                                                                                                var r = make(int, len(a))
                                                                                                                                                for i,v := range a{
                                                                                                                                                r[i] = m[v]
                                                                                                                                                m[v]++
                                                                                                                                                }
                                                                                                                                                return r
                                                                                                                                                }


                                                                                                                                                Accepts integer array and returns integer array.






                                                                                                                                                share|improve this answer








                                                                                                                                                New contributor




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














                                                                                                                                                • 3




                                                                                                                                                  Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                  – Adám
                                                                                                                                                  19 hours ago














                                                                                                                                                0












                                                                                                                                                0








                                                                                                                                                0






                                                                                                                                                GO 121 Bytes (Not included new lines and tabs)



                                                                                                                                                func cg(a int) int{
                                                                                                                                                var m = make(map[int]int)
                                                                                                                                                var r = make(int, len(a))
                                                                                                                                                for i,v := range a{
                                                                                                                                                r[i] = m[v]
                                                                                                                                                m[v]++
                                                                                                                                                }
                                                                                                                                                return r
                                                                                                                                                }


                                                                                                                                                Accepts integer array and returns integer array.






                                                                                                                                                share|improve this answer








                                                                                                                                                New contributor




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









                                                                                                                                                GO 121 Bytes (Not included new lines and tabs)



                                                                                                                                                func cg(a int) int{
                                                                                                                                                var m = make(map[int]int)
                                                                                                                                                var r = make(int, len(a))
                                                                                                                                                for i,v := range a{
                                                                                                                                                r[i] = m[v]
                                                                                                                                                m[v]++
                                                                                                                                                }
                                                                                                                                                return r
                                                                                                                                                }


                                                                                                                                                Accepts integer array and returns integer array.







                                                                                                                                                share|improve this answer








                                                                                                                                                New contributor




                                                                                                                                                rock star 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 answer



                                                                                                                                                share|improve this answer






                                                                                                                                                New contributor




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









                                                                                                                                                answered yesterday









                                                                                                                                                rock starrock star

                                                                                                                                                101




                                                                                                                                                101




                                                                                                                                                New contributor




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





                                                                                                                                                New contributor





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






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








                                                                                                                                                • 3




                                                                                                                                                  Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                  – Adám
                                                                                                                                                  19 hours ago














                                                                                                                                                • 3




                                                                                                                                                  Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                  – Adám
                                                                                                                                                  19 hours ago








                                                                                                                                                3




                                                                                                                                                3




                                                                                                                                                Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                – Adám
                                                                                                                                                19 hours ago




                                                                                                                                                Welcome to PPCG. Rare to see Go represented here. You do need to count necessary newlines, but you also have a lot of spaces that can be removed, and you can also shorten cg to c. I recommend using TIO to generate the main part of your post: Try it online!
                                                                                                                                                – Adám
                                                                                                                                                19 hours ago











                                                                                                                                                0














                                                                                                                                                C++,137 bytes
                                                                                                                                                //v is input , ov is output ; //example to populate v: vector v{7,8,7};



                                                                                                                                                vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});





                                                                                                                                                share|improve this answer










                                                                                                                                                New contributor




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


















                                                                                                                                                • I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                  – Stephen
                                                                                                                                                  yesterday






                                                                                                                                                • 1




                                                                                                                                                  I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                  – Jo King
                                                                                                                                                  19 hours ago
















                                                                                                                                                0














                                                                                                                                                C++,137 bytes
                                                                                                                                                //v is input , ov is output ; //example to populate v: vector v{7,8,7};



                                                                                                                                                vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});





                                                                                                                                                share|improve this answer










                                                                                                                                                New contributor




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


















                                                                                                                                                • I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                  – Stephen
                                                                                                                                                  yesterday






                                                                                                                                                • 1




                                                                                                                                                  I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                  – Jo King
                                                                                                                                                  19 hours ago














                                                                                                                                                0












                                                                                                                                                0








                                                                                                                                                0






                                                                                                                                                C++,137 bytes
                                                                                                                                                //v is input , ov is output ; //example to populate v: vector v{7,8,7};



                                                                                                                                                vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});





                                                                                                                                                share|improve this answer










                                                                                                                                                New contributor




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









                                                                                                                                                C++,137 bytes
                                                                                                                                                //v is input , ov is output ; //example to populate v: vector v{7,8,7};



                                                                                                                                                vector<int> v,ov(v.size());map<int,int>m;transform(begin(v),end(v),begin(ov),[&m](int i){!m.count(i)?m[i]=0:m[i]+=1;return m[i];});






                                                                                                                                                share|improve this answer










                                                                                                                                                New contributor




                                                                                                                                                qqqqq 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 answer



                                                                                                                                                share|improve this answer








                                                                                                                                                edited 10 hours ago





















                                                                                                                                                New contributor




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









                                                                                                                                                answered yesterday









                                                                                                                                                qqqqqqqqqq

                                                                                                                                                1012




                                                                                                                                                1012




                                                                                                                                                New contributor




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





                                                                                                                                                New contributor





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






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












                                                                                                                                                • I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                  – Stephen
                                                                                                                                                  yesterday






                                                                                                                                                • 1




                                                                                                                                                  I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                  – Jo King
                                                                                                                                                  19 hours ago


















                                                                                                                                                • I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                  – Stephen
                                                                                                                                                  yesterday






                                                                                                                                                • 1




                                                                                                                                                  I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                  – Jo King
                                                                                                                                                  19 hours ago
















                                                                                                                                                I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                – Stephen
                                                                                                                                                yesterday




                                                                                                                                                I'm not sure about C++, but can't you remove the newlines to save 2 bytes?
                                                                                                                                                – Stephen
                                                                                                                                                yesterday




                                                                                                                                                1




                                                                                                                                                1




                                                                                                                                                I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                – Jo King
                                                                                                                                                19 hours ago




                                                                                                                                                I don't know C++ either, but what is this? It doesn't look like a function, and I don't see how you take input?
                                                                                                                                                – Jo King
                                                                                                                                                19 hours ago











                                                                                                                                                0















                                                                                                                                                Python 2, 44 bytes





                                                                                                                                                a=
                                                                                                                                                for x in input():print a.count(x);a+=x,


                                                                                                                                                Try it online!



                                                                                                                                                The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.






                                                                                                                                                share|improve this answer


























                                                                                                                                                  0















                                                                                                                                                  Python 2, 44 bytes





                                                                                                                                                  a=
                                                                                                                                                  for x in input():print a.count(x);a+=x,


                                                                                                                                                  Try it online!



                                                                                                                                                  The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.






                                                                                                                                                  share|improve this answer
























                                                                                                                                                    0












                                                                                                                                                    0








                                                                                                                                                    0







                                                                                                                                                    Python 2, 44 bytes





                                                                                                                                                    a=
                                                                                                                                                    for x in input():print a.count(x);a+=x,


                                                                                                                                                    Try it online!



                                                                                                                                                    The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.






                                                                                                                                                    share|improve this answer













                                                                                                                                                    Python 2, 44 bytes





                                                                                                                                                    a=
                                                                                                                                                    for x in input():print a.count(x);a+=x,


                                                                                                                                                    Try it online!



                                                                                                                                                    The first thing I wrote tied Chas Brown's 43, so here's a different solution that's one byte longer.







                                                                                                                                                    share|improve this answer












                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer










                                                                                                                                                    answered 5 hours ago









                                                                                                                                                    LynnLynn

                                                                                                                                                    49.5k794227




                                                                                                                                                    49.5k794227






























                                                                                                                                                        draft saved

                                                                                                                                                        draft discarded




















































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






                                                                                                                                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                                                                                                                        Please pay close attention to the following guidance:


                                                                                                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                                                                                                        But avoid



                                                                                                                                                        • Asking for help, clarification, or responding to other answers.

                                                                                                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                                                        To learn more, see our tips on writing great answers.




                                                                                                                                                        draft saved


                                                                                                                                                        draft discarded














                                                                                                                                                        StackExchange.ready(
                                                                                                                                                        function () {
                                                                                                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178500%2fenumerate-each-series-of-identical-numbers-in-place%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

                                                                                                                                                        1300-talet

                                                                                                                                                        1300-talet

                                                                                                                                                        Has there ever been an instance of an active nuclear power plant within or near a war zone?