Enumerate each series of identical numbers in-place












18














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
    2 days ago






  • 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
    2 days ago
















18














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
    2 days ago






  • 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
    2 days ago














18












18








18







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 2 days ago









AdámAdám

29k269192




29k269192








  • 2




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






  • 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
    2 days ago














  • 2




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






  • 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
    2 days ago








2




2




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




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




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
2 days ago




@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
2 days ago










30 Answers
30






active

oldest

votes


















20














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
    2 days ago










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












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












  • @DaveMongoose Tips for golfing in JavaScript
    – user202729
    2 days ago








  • 1




    @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
    – ASCII-only
    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
    2 days ago



















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
      2 days ago










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



















    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















        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
          2 days ago










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






        • 1




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



















        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
              2 days ago



















            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
                  2 days ago










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












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



















                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
                  2 days ago



















                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
                  2 days ago










                • 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
                  2 days ago





















                1















                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

















                • 1




                  A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                  – Laikoni
                  12 hours ago












                • @Laikoni: How did you even come up with that, you should totally post it!
                  – BMO
                  12 hours ago






                • 1




                  Done: codegolf.stackexchange.com/a/178629/56433
                  – Laikoni
                  11 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
                  yesterday





















                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
                  2 days 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
                  yesterday






                • 2




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



















                1















                Haskell, 47 46 bytes





                (#(*0))
                (x:r)#g=g x:r# y->0^(y-x)^2+g y
                e#g=e


                Try it online!



                A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)



                The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g. Ungolfed:



                f (const 0)
                f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
                f g =


                Two interesting golfing opportunities arose. First for the initial value of g, a constant function which disregards its argument and returns 0:



                const 0  -- the idiomatic way
                (_->0) -- can be shorter if parenthesis are not needed
                min 0 -- only works as inputs are guaranteed to be non-negative
                (0*) -- obvious in hindsight but took me a while to think of


                And secondly an expression over variables x and y which yields 1 if x equals y and 0 otherwise:



                if x==y then 1else 0  -- yes you don't need a space after the 1
                fromEnum$x==y -- works because Bool is an instance of Enum
                sum[1|x==y] -- uses that the sum of an empty list is zero
                0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
                0^(x-y)^2 -- Thanks to Christian Sievers!


                There still might be shorter ways. Anyone got an idea?






                share|improve this answer



















                • 1




                  You can use 0^(x-y)^2.
                  – Christian Sievers
                  8 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





















                    • I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                      – Dennis
                      6 hours ago



















                    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














                        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
                            yesterday



















                          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
                            2 days ago






                          • 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
                            yesterday










                          • You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                            – Jo King
                            11 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















                            Reticular, 17 bytes



                            L[ddc@c~]~*$qlbo;


                            Try it online!



                            The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:



                            '2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;


                            Explanation



                            The pop instruction c which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.



                            L                 # Push length of input list to the stack.
                            [ ] # Push the following function:
                            dd # Duplicate top of stack twice.
                            c # Pop the list at top of the stack,
                            pop the last element in the list (which will pop the element of every list!)
                            and finally push it to the stack.
                            @c # Pop two items at the top of the stack (list + last element in that list).
                            then push the number of occurrences of that element in the list.
                            ~ # Swap top two items in the stack (so that the popped list is on top again).
                            ~ # Swap top two items in the stack.
                            * # Call the above function the same number of times as length of the input list.
                            $ # Remove the item at the top of the stack (which by now is an empty list).
                            q # Reverse stack.
                            lb # Push size of stack and put that many items from the stack into a list.
                            o; # Output resulting list and exit.





                            share|improve this answer





























                              0















                              SNOBOL4 (CSNOBOL4), 63 bytes



                               T =TABLE()
                              R I =INPUT :F(END)
                              T<I> =OUTPUT =T<I> + 1 :(R)
                              END


                              Try it online!






                              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

























                                30 Answers
                                30






                                active

                                oldest

                                votes








                                30 Answers
                                30






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes









                                20














                                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
                                  2 days ago










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












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












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  2 days ago








                                • 1




                                  @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                  – ASCII-only
                                  yesterday


















                                20














                                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
                                  2 days ago










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












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












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  2 days ago








                                • 1




                                  @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                  – ASCII-only
                                  yesterday
















                                20












                                20








                                20






                                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 2 days ago

























                                answered 2 days ago









                                ArnauldArnauld

                                72.9k689307




                                72.9k689307








                                • 1




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










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












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












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  2 days ago








                                • 1




                                  @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                  – ASCII-only
                                  yesterday
















                                • 1




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










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












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












                                • @DaveMongoose Tips for golfing in JavaScript
                                  – user202729
                                  2 days ago








                                • 1




                                  @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                  – ASCII-only
                                  yesterday










                                1




                                1




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




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












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






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














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






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














                                @DaveMongoose Tips for golfing in JavaScript
                                – user202729
                                2 days ago






                                @DaveMongoose Tips for golfing in JavaScript
                                – user202729
                                2 days ago






                                1




                                1




                                @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                – ASCII-only
                                yesterday






                                @DaveMongoose -~ is actually a commonly used alternative to +1 (since it has different precedence) in many languages
                                – ASCII-only
                                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
                                  2 days ago
















                                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
                                  2 days ago














                                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 2 days ago

























                                answered 2 days ago









                                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
                                  2 days ago














                                • 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
                                  2 days ago








                                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
                                2 days ago




                                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
                                2 days ago











                                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 2 days ago

























                                    answered 2 days ago









                                    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
                                          2 days ago










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
















                                        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
                                          2 days ago










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














                                        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 yesterday

























                                        answered 2 days ago









                                        Galen IvanovGalen Ivanov

                                        6,44711032




                                        6,44711032








                                        • 1




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










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














                                        • 1




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










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








                                        1




                                        1




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




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












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




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











                                        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 2 days ago









                                            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 2 days ago









                                                    EmignaEmigna

                                                    45.5k432138




                                                    45.5k432138























                                                        3















                                                        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
                                                          2 days ago










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






                                                        • 1




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
















                                                        3















                                                        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
                                                          2 days ago










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






                                                        • 1




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














                                                        3












                                                        3








                                                        3







                                                        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 2 days ago

























                                                        answered 2 days ago









                                                        danadana

                                                        58135




                                                        58135












                                                        • 22 bytes
                                                          – LiefdeWen
                                                          2 days ago










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






                                                        • 1




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


















                                                        • 22 bytes
                                                          – LiefdeWen
                                                          2 days ago










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






                                                        • 1




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
















                                                        22 bytes
                                                        – LiefdeWen
                                                        2 days ago




                                                        22 bytes
                                                        – LiefdeWen
                                                        2 days ago












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




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




                                                        1




                                                        1




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




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











                                                        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 2 days ago

























                                                            answered 2 days ago









                                                            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 2 days ago

























                                                                    answered 2 days ago









                                                                    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
                                                                          2 days ago
















                                                                        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
                                                                          2 days ago














                                                                        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 2 days ago









                                                                        Mr. XcoderMr. Xcoder

                                                                        31.7k759198




                                                                        31.7k759198












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


















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
















                                                                        Alternatively the old-school ;ċ" is also 4.
                                                                        – Jonathan Allan
                                                                        2 days ago




                                                                        Alternatively the old-school ;ċ" is also 4.
                                                                        – Jonathan Allan
                                                                        2 days ago











                                                                        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 2 days ago









                                                                            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 yesterday

























                                                                                    answered 2 days ago









                                                                                    Jo KingJo King

                                                                                    21.2k248110




                                                                                    21.2k248110























                                                                                        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
                                                                                          2 days ago










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












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
















                                                                                        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
                                                                                          2 days ago










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












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














                                                                                        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 2 days ago









                                                                                        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
                                                                                          2 days ago










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












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


















                                                                                        • 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
                                                                                          2 days ago










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












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
















                                                                                        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
                                                                                        2 days ago




                                                                                        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
                                                                                        2 days ago












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






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














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




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











                                                                                        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
                                                                                          2 days ago
















                                                                                        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
                                                                                          2 days ago














                                                                                        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 2 days ago

























                                                                                        answered 2 days ago









                                                                                        Olivier GrégoireOlivier Grégoire

                                                                                        8,84711843




                                                                                        8,84711843








                                                                                        • 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
                                                                                          2 days ago














                                                                                        • 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
                                                                                          2 days ago








                                                                                        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
                                                                                        2 days ago




                                                                                        -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
                                                                                        2 days ago











                                                                                        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
                                                                                          2 days ago










                                                                                        • 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
                                                                                          2 days ago


















                                                                                        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
                                                                                          2 days ago










                                                                                        • 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
                                                                                          2 days ago
















                                                                                        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 2 days ago

























                                                                                        answered 2 days ago









                                                                                        Sumner18Sumner18

                                                                                        4007




                                                                                        4007












                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          2 days ago










                                                                                        • 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
                                                                                          2 days ago




















                                                                                        • you can remove the which() to save 7 bytes.
                                                                                          – Giuseppe
                                                                                          2 days ago










                                                                                        • 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
                                                                                          2 days ago


















                                                                                        you can remove the which() to save 7 bytes.
                                                                                        – Giuseppe
                                                                                        2 days ago




                                                                                        you can remove the which() to save 7 bytes.
                                                                                        – Giuseppe
                                                                                        2 days ago












                                                                                        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
                                                                                        2 days ago






                                                                                        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
                                                                                        2 days ago













                                                                                        1















                                                                                        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

















                                                                                        • 1




                                                                                          A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                          – Laikoni
                                                                                          12 hours ago












                                                                                        • @Laikoni: How did you even come up with that, you should totally post it!
                                                                                          – BMO
                                                                                          12 hours ago






                                                                                        • 1




                                                                                          Done: codegolf.stackexchange.com/a/178629/56433
                                                                                          – Laikoni
                                                                                          11 hours ago
















                                                                                        1















                                                                                        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

















                                                                                        • 1




                                                                                          A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                          – Laikoni
                                                                                          12 hours ago












                                                                                        • @Laikoni: How did you even come up with that, you should totally post it!
                                                                                          – BMO
                                                                                          12 hours ago






                                                                                        • 1




                                                                                          Done: codegolf.stackexchange.com/a/178629/56433
                                                                                          – Laikoni
                                                                                          11 hours ago














                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        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 2 days ago









                                                                                        BMOBMO

                                                                                        11.8k22188




                                                                                        11.8k22188








                                                                                        • 1




                                                                                          A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                          – Laikoni
                                                                                          12 hours ago












                                                                                        • @Laikoni: How did you even come up with that, you should totally post it!
                                                                                          – BMO
                                                                                          12 hours ago






                                                                                        • 1




                                                                                          Done: codegolf.stackexchange.com/a/178629/56433
                                                                                          – Laikoni
                                                                                          11 hours ago














                                                                                        • 1




                                                                                          A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                          – Laikoni
                                                                                          12 hours ago












                                                                                        • @Laikoni: How did you even come up with that, you should totally post it!
                                                                                          – BMO
                                                                                          12 hours ago






                                                                                        • 1




                                                                                          Done: codegolf.stackexchange.com/a/178629/56433
                                                                                          – Laikoni
                                                                                          11 hours ago








                                                                                        1




                                                                                        1




                                                                                        A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                        – Laikoni
                                                                                        12 hours ago






                                                                                        A bit longer but maybe nevertheless interesting: (#(0*));(x:r)#g=g x:r# y->0^abs(y-x)+g y;e#g=e Try it online!
                                                                                        – Laikoni
                                                                                        12 hours ago














                                                                                        @Laikoni: How did you even come up with that, you should totally post it!
                                                                                        – BMO
                                                                                        12 hours ago




                                                                                        @Laikoni: How did you even come up with that, you should totally post it!
                                                                                        – BMO
                                                                                        12 hours ago




                                                                                        1




                                                                                        1




                                                                                        Done: codegolf.stackexchange.com/a/178629/56433
                                                                                        – Laikoni
                                                                                        11 hours ago




                                                                                        Done: codegolf.stackexchange.com/a/178629/56433
                                                                                        – Laikoni
                                                                                        11 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
                                                                                          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
                                                                                          yesterday
















                                                                                        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 2 days ago









                                                                                        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
                                                                                          yesterday




















                                                                                        • 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
                                                                                          yesterday


















                                                                                        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
                                                                                        yesterday






                                                                                        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
                                                                                        yesterday













                                                                                        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
                                                                                          2 days 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
                                                                                          yesterday






                                                                                        • 2




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
















                                                                                        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
                                                                                          2 days 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
                                                                                          yesterday






                                                                                        • 2




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














                                                                                        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 yesterday

























                                                                                        answered 2 days ago









                                                                                        Nahuel FouilleulNahuel Fouilleul

                                                                                        1,64228




                                                                                        1,64228








                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          2 days 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
                                                                                          yesterday






                                                                                        • 2




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














                                                                                        • 1




                                                                                          Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                          – Digital Trauma
                                                                                          2 days 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
                                                                                          yesterday






                                                                                        • 2




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








                                                                                        1




                                                                                        1




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




                                                                                        Pass the list as command line args - tio.run/##S0oszvj/Py2/SKHCuporNTkjX0ElOjG6IlZbO5ar9v///8b/… - only 24 bytes.
                                                                                        – Digital Trauma
                                                                                        2 days 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
                                                                                        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
                                                                                        yesterday




                                                                                        2




                                                                                        2




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




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











                                                                                        1















                                                                                        Haskell, 47 46 bytes





                                                                                        (#(*0))
                                                                                        (x:r)#g=g x:r# y->0^(y-x)^2+g y
                                                                                        e#g=e


                                                                                        Try it online!



                                                                                        A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)



                                                                                        The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g. Ungolfed:



                                                                                        f (const 0)
                                                                                        f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
                                                                                        f g =


                                                                                        Two interesting golfing opportunities arose. First for the initial value of g, a constant function which disregards its argument and returns 0:



                                                                                        const 0  -- the idiomatic way
                                                                                        (_->0) -- can be shorter if parenthesis are not needed
                                                                                        min 0 -- only works as inputs are guaranteed to be non-negative
                                                                                        (0*) -- obvious in hindsight but took me a while to think of


                                                                                        And secondly an expression over variables x and y which yields 1 if x equals y and 0 otherwise:



                                                                                        if x==y then 1else 0  -- yes you don't need a space after the 1
                                                                                        fromEnum$x==y -- works because Bool is an instance of Enum
                                                                                        sum[1|x==y] -- uses that the sum of an empty list is zero
                                                                                        0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
                                                                                        0^(x-y)^2 -- Thanks to Christian Sievers!


                                                                                        There still might be shorter ways. Anyone got an idea?






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          You can use 0^(x-y)^2.
                                                                                          – Christian Sievers
                                                                                          8 hours ago
















                                                                                        1















                                                                                        Haskell, 47 46 bytes





                                                                                        (#(*0))
                                                                                        (x:r)#g=g x:r# y->0^(y-x)^2+g y
                                                                                        e#g=e


                                                                                        Try it online!



                                                                                        A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)



                                                                                        The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g. Ungolfed:



                                                                                        f (const 0)
                                                                                        f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
                                                                                        f g =


                                                                                        Two interesting golfing opportunities arose. First for the initial value of g, a constant function which disregards its argument and returns 0:



                                                                                        const 0  -- the idiomatic way
                                                                                        (_->0) -- can be shorter if parenthesis are not needed
                                                                                        min 0 -- only works as inputs are guaranteed to be non-negative
                                                                                        (0*) -- obvious in hindsight but took me a while to think of


                                                                                        And secondly an expression over variables x and y which yields 1 if x equals y and 0 otherwise:



                                                                                        if x==y then 1else 0  -- yes you don't need a space after the 1
                                                                                        fromEnum$x==y -- works because Bool is an instance of Enum
                                                                                        sum[1|x==y] -- uses that the sum of an empty list is zero
                                                                                        0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
                                                                                        0^(x-y)^2 -- Thanks to Christian Sievers!


                                                                                        There still might be shorter ways. Anyone got an idea?






                                                                                        share|improve this answer



















                                                                                        • 1




                                                                                          You can use 0^(x-y)^2.
                                                                                          – Christian Sievers
                                                                                          8 hours ago














                                                                                        1












                                                                                        1








                                                                                        1







                                                                                        Haskell, 47 46 bytes





                                                                                        (#(*0))
                                                                                        (x:r)#g=g x:r# y->0^(y-x)^2+g y
                                                                                        e#g=e


                                                                                        Try it online!



                                                                                        A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)



                                                                                        The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g. Ungolfed:



                                                                                        f (const 0)
                                                                                        f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
                                                                                        f g =


                                                                                        Two interesting golfing opportunities arose. First for the initial value of g, a constant function which disregards its argument and returns 0:



                                                                                        const 0  -- the idiomatic way
                                                                                        (_->0) -- can be shorter if parenthesis are not needed
                                                                                        min 0 -- only works as inputs are guaranteed to be non-negative
                                                                                        (0*) -- obvious in hindsight but took me a while to think of


                                                                                        And secondly an expression over variables x and y which yields 1 if x equals y and 0 otherwise:



                                                                                        if x==y then 1else 0  -- yes you don't need a space after the 1
                                                                                        fromEnum$x==y -- works because Bool is an instance of Enum
                                                                                        sum[1|x==y] -- uses that the sum of an empty list is zero
                                                                                        0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
                                                                                        0^(x-y)^2 -- Thanks to Christian Sievers!


                                                                                        There still might be shorter ways. Anyone got an idea?






                                                                                        share|improve this answer















                                                                                        Haskell, 47 46 bytes





                                                                                        (#(*0))
                                                                                        (x:r)#g=g x:r# y->0^(y-x)^2+g y
                                                                                        e#g=e


                                                                                        Try it online!



                                                                                        A different approach than BMO's answer which turned out a bit longer. (And kindly borrows their nice test suit.)



                                                                                        The idea is to iterate over the input list and keep track of the number of times each element has occurred by updating a function g. Ungolfed:



                                                                                        f (const 0)
                                                                                        f g (x:r) = g x : f ( y -> if x==y then 1 + g y else g y) r
                                                                                        f g =


                                                                                        Two interesting golfing opportunities arose. First for the initial value of g, a constant function which disregards its argument and returns 0:



                                                                                        const 0  -- the idiomatic way
                                                                                        (_->0) -- can be shorter if parenthesis are not needed
                                                                                        min 0 -- only works as inputs are guaranteed to be non-negative
                                                                                        (0*) -- obvious in hindsight but took me a while to think of


                                                                                        And secondly an expression over variables x and y which yields 1 if x equals y and 0 otherwise:



                                                                                        if x==y then 1else 0  -- yes you don't need a space after the 1
                                                                                        fromEnum$x==y -- works because Bool is an instance of Enum
                                                                                        sum[1|x==y] -- uses that the sum of an empty list is zero
                                                                                        0^abs(x-y) -- uses that 0^0=1 and 0^x=0 for any positive x
                                                                                        0^(x-y)^2 -- Thanks to Christian Sievers!


                                                                                        There still might be shorter ways. Anyone got an idea?







                                                                                        share|improve this answer














                                                                                        share|improve this answer



                                                                                        share|improve this answer








                                                                                        edited 8 hours ago

























                                                                                        answered 11 hours ago









                                                                                        LaikoniLaikoni

                                                                                        19.8k43699




                                                                                        19.8k43699








                                                                                        • 1




                                                                                          You can use 0^(x-y)^2.
                                                                                          – Christian Sievers
                                                                                          8 hours ago














                                                                                        • 1




                                                                                          You can use 0^(x-y)^2.
                                                                                          – Christian Sievers
                                                                                          8 hours ago








                                                                                        1




                                                                                        1




                                                                                        You can use 0^(x-y)^2.
                                                                                        – Christian Sievers
                                                                                        8 hours ago




                                                                                        You can use 0^(x-y)^2.
                                                                                        – Christian Sievers
                                                                                        8 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 2 days ago









                                                                                            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 2 days ago









                                                                                                    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





















                                                                                                        • I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                          – Dennis
                                                                                                          6 hours ago
















                                                                                                        0














                                                                                                        awk (46 bytes)



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


                                                                                                        TIO






                                                                                                        share|improve this answer





















                                                                                                        • I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                          – Dennis
                                                                                                          6 hours ago














                                                                                                        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 2 days ago









                                                                                                        Nahuel FouilleulNahuel Fouilleul

                                                                                                        1,64228




                                                                                                        1,64228












                                                                                                        • I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                          – Dennis
                                                                                                          6 hours ago


















                                                                                                        • I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                          – Dennis
                                                                                                          6 hours ago
















                                                                                                        I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                        – Dennis
                                                                                                        6 hours ago




                                                                                                        I think {for(;i++<NF;)$i=a[$i]++;print} works. delete(a); is only needed for the test suite, no?
                                                                                                        – Dennis
                                                                                                        6 hours ago











                                                                                                        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 2 days ago

























                                                                                                            answered 2 days ago









                                                                                                            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 2 days ago

























                                                                                                                    answered 2 days ago









                                                                                                                    ShaggyShaggy

                                                                                                                    19.2k21666




                                                                                                                    19.2k21666























                                                                                                                        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 2 days ago









                                                                                                                            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
                                                                                                                                  yesterday
















                                                                                                                                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
                                                                                                                                  yesterday














                                                                                                                                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 2 days ago









                                                                                                                                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
                                                                                                                                  yesterday














                                                                                                                                • 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
                                                                                                                                  yesterday








                                                                                                                                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
                                                                                                                                yesterday




                                                                                                                                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
                                                                                                                                yesterday











                                                                                                                                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
                                                                                                                                  2 days ago






                                                                                                                                • 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
                                                                                                                                  yesterday










                                                                                                                                • You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                  – Jo King
                                                                                                                                  11 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
                                                                                                                                  2 days ago






                                                                                                                                • 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
                                                                                                                                  yesterday










                                                                                                                                • You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                  – Jo King
                                                                                                                                  11 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 yesterday





















                                                                                                                                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 2 days ago









                                                                                                                                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
                                                                                                                                  2 days ago






                                                                                                                                • 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
                                                                                                                                  yesterday










                                                                                                                                • You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                  – Jo King
                                                                                                                                  11 hours ago


















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






                                                                                                                                • 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
                                                                                                                                  yesterday










                                                                                                                                • You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                  – Jo King
                                                                                                                                  11 hours ago
















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




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




                                                                                                                                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
                                                                                                                                yesterday




                                                                                                                                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
                                                                                                                                yesterday












                                                                                                                                You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                – Jo King
                                                                                                                                11 hours ago




                                                                                                                                You can't take input via a predefined variable, otherwise this becomes a snippet. Submissions have to be a full program or a function
                                                                                                                                – Jo King
                                                                                                                                11 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 yesterday









                                                                                                                                    LynnLynn

                                                                                                                                    49.5k794227




                                                                                                                                    49.5k794227























                                                                                                                                        0















                                                                                                                                        Reticular, 17 bytes



                                                                                                                                        L[ddc@c~]~*$qlbo;


                                                                                                                                        Try it online!



                                                                                                                                        The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:



                                                                                                                                        '2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;


                                                                                                                                        Explanation



                                                                                                                                        The pop instruction c which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.



                                                                                                                                        L                 # Push length of input list to the stack.
                                                                                                                                        [ ] # Push the following function:
                                                                                                                                        dd # Duplicate top of stack twice.
                                                                                                                                        c # Pop the list at top of the stack,
                                                                                                                                        pop the last element in the list (which will pop the element of every list!)
                                                                                                                                        and finally push it to the stack.
                                                                                                                                        @c # Pop two items at the top of the stack (list + last element in that list).
                                                                                                                                        then push the number of occurrences of that element in the list.
                                                                                                                                        ~ # Swap top two items in the stack (so that the popped list is on top again).
                                                                                                                                        ~ # Swap top two items in the stack.
                                                                                                                                        * # Call the above function the same number of times as length of the input list.
                                                                                                                                        $ # Remove the item at the top of the stack (which by now is an empty list).
                                                                                                                                        q # Reverse stack.
                                                                                                                                        lb # Push size of stack and put that many items from the stack into a list.
                                                                                                                                        o; # Output resulting list and exit.





                                                                                                                                        share|improve this answer


























                                                                                                                                          0















                                                                                                                                          Reticular, 17 bytes



                                                                                                                                          L[ddc@c~]~*$qlbo;


                                                                                                                                          Try it online!



                                                                                                                                          The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:



                                                                                                                                          '2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;


                                                                                                                                          Explanation



                                                                                                                                          The pop instruction c which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.



                                                                                                                                          L                 # Push length of input list to the stack.
                                                                                                                                          [ ] # Push the following function:
                                                                                                                                          dd # Duplicate top of stack twice.
                                                                                                                                          c # Pop the list at top of the stack,
                                                                                                                                          pop the last element in the list (which will pop the element of every list!)
                                                                                                                                          and finally push it to the stack.
                                                                                                                                          @c # Pop two items at the top of the stack (list + last element in that list).
                                                                                                                                          then push the number of occurrences of that element in the list.
                                                                                                                                          ~ # Swap top two items in the stack (so that the popped list is on top again).
                                                                                                                                          ~ # Swap top two items in the stack.
                                                                                                                                          * # Call the above function the same number of times as length of the input list.
                                                                                                                                          $ # Remove the item at the top of the stack (which by now is an empty list).
                                                                                                                                          q # Reverse stack.
                                                                                                                                          lb # Push size of stack and put that many items from the stack into a list.
                                                                                                                                          o; # Output resulting list and exit.





                                                                                                                                          share|improve this answer
























                                                                                                                                            0












                                                                                                                                            0








                                                                                                                                            0







                                                                                                                                            Reticular, 17 bytes



                                                                                                                                            L[ddc@c~]~*$qlbo;


                                                                                                                                            Try it online!



                                                                                                                                            The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:



                                                                                                                                            '2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;


                                                                                                                                            Explanation



                                                                                                                                            The pop instruction c which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.



                                                                                                                                            L                 # Push length of input list to the stack.
                                                                                                                                            [ ] # Push the following function:
                                                                                                                                            dd # Duplicate top of stack twice.
                                                                                                                                            c # Pop the list at top of the stack,
                                                                                                                                            pop the last element in the list (which will pop the element of every list!)
                                                                                                                                            and finally push it to the stack.
                                                                                                                                            @c # Pop two items at the top of the stack (list + last element in that list).
                                                                                                                                            then push the number of occurrences of that element in the list.
                                                                                                                                            ~ # Swap top two items in the stack (so that the popped list is on top again).
                                                                                                                                            ~ # Swap top two items in the stack.
                                                                                                                                            * # Call the above function the same number of times as length of the input list.
                                                                                                                                            $ # Remove the item at the top of the stack (which by now is an empty list).
                                                                                                                                            q # Reverse stack.
                                                                                                                                            lb # Push size of stack and put that many items from the stack into a list.
                                                                                                                                            o; # Output resulting list and exit.





                                                                                                                                            share|improve this answer













                                                                                                                                            Reticular, 17 bytes



                                                                                                                                            L[ddc@c~]~*$qlbo;


                                                                                                                                            Try it online!



                                                                                                                                            The input list of integers is assumed to already be pushed to the stack. Run the following code to test input:



                                                                                                                                            '2''7''1''8''2''8''1''8''2''8'lbL[ddc@c~]~*$qlbo;


                                                                                                                                            Explanation



                                                                                                                                            The pop instruction c which is supposed to: pop a list from the stack, pop the last element from that list and push this element to the stack. However, if the list occurs at more than 1 place in the stack (if it has been duplicated for example), all of the duplicated lists in the stack will also have their last element popped contrary to what one might think will happen. This is fortunately used in our favor in this puzzle.



                                                                                                                                            L                 # Push length of input list to the stack.
                                                                                                                                            [ ] # Push the following function:
                                                                                                                                            dd # Duplicate top of stack twice.
                                                                                                                                            c # Pop the list at top of the stack,
                                                                                                                                            pop the last element in the list (which will pop the element of every list!)
                                                                                                                                            and finally push it to the stack.
                                                                                                                                            @c # Pop two items at the top of the stack (list + last element in that list).
                                                                                                                                            then push the number of occurrences of that element in the list.
                                                                                                                                            ~ # Swap top two items in the stack (so that the popped list is on top again).
                                                                                                                                            ~ # Swap top two items in the stack.
                                                                                                                                            * # Call the above function the same number of times as length of the input list.
                                                                                                                                            $ # Remove the item at the top of the stack (which by now is an empty list).
                                                                                                                                            q # Reverse stack.
                                                                                                                                            lb # Push size of stack and put that many items from the stack into a list.
                                                                                                                                            o; # Output resulting list and exit.






                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered 7 hours ago









                                                                                                                                            WisławWisław

                                                                                                                                            1113




                                                                                                                                            1113























                                                                                                                                                0















                                                                                                                                                SNOBOL4 (CSNOBOL4), 63 bytes



                                                                                                                                                 T =TABLE()
                                                                                                                                                R I =INPUT :F(END)
                                                                                                                                                T<I> =OUTPUT =T<I> + 1 :(R)
                                                                                                                                                END


                                                                                                                                                Try it online!






                                                                                                                                                share|improve this answer


























                                                                                                                                                  0















                                                                                                                                                  SNOBOL4 (CSNOBOL4), 63 bytes



                                                                                                                                                   T =TABLE()
                                                                                                                                                  R I =INPUT :F(END)
                                                                                                                                                  T<I> =OUTPUT =T<I> + 1 :(R)
                                                                                                                                                  END


                                                                                                                                                  Try it online!






                                                                                                                                                  share|improve this answer
























                                                                                                                                                    0












                                                                                                                                                    0








                                                                                                                                                    0







                                                                                                                                                    SNOBOL4 (CSNOBOL4), 63 bytes



                                                                                                                                                     T =TABLE()
                                                                                                                                                    R I =INPUT :F(END)
                                                                                                                                                    T<I> =OUTPUT =T<I> + 1 :(R)
                                                                                                                                                    END


                                                                                                                                                    Try it online!






                                                                                                                                                    share|improve this answer













                                                                                                                                                    SNOBOL4 (CSNOBOL4), 63 bytes



                                                                                                                                                     T =TABLE()
                                                                                                                                                    R I =INPUT :F(END)
                                                                                                                                                    T<I> =OUTPUT =T<I> + 1 :(R)
                                                                                                                                                    END


                                                                                                                                                    Try it online!







                                                                                                                                                    share|improve this answer












                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer










                                                                                                                                                    answered 7 hours ago









                                                                                                                                                    GiuseppeGiuseppe

                                                                                                                                                    16.6k31052




                                                                                                                                                    16.6k31052






























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





                                                                                                                                                        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

                                                                                                                                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                                                                                                                                        Alcedinidae

                                                                                                                                                        Origin of the phrase “under your belt”?