Same number letters

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












Letters of the words want fairness



they decided to appear same number of times in a sentence equally



Example



Priorities


will become



Ppprrioooritttieeesss


each letter show 3 times as letter mostly used was i and it showed 3 times



it does not matter where you put the repeated letters as log as they next to a similar letter



means



Pppriooorritttieeesss is ok (the r letter)



Ppprioororitttieeesss is no ok (the r letter)



another example



invoice


will become



innvvooiccee


another example



Remittance Advice


will become



Rrremmmiitttaannncce Adddvvvice


Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same



the form of the letter does not matter, either cap or small will count as the same letter, Pip has 2 Ps and 1 I so it will become Piip



It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP



This is code-golf










share|improve this question



















  • 1




    How do we deal with capital letters?
    – xnor
    4 hours ago










  • Caps and small no difference, you can use either
    – asmgx
    4 hours ago







  • 1




    Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
    – Shieru Asakoto
    4 hours ago






  • 1




    @JonathanAllan will fix this now
    – asmgx
    11 mins ago






  • 2




    can we change the case of capitalised letters? e.g. Can Pip result in piip?
    – Jo King
    7 mins ago














up vote
2
down vote

favorite












Letters of the words want fairness



they decided to appear same number of times in a sentence equally



Example



Priorities


will become



Ppprrioooritttieeesss


each letter show 3 times as letter mostly used was i and it showed 3 times



it does not matter where you put the repeated letters as log as they next to a similar letter



means



Pppriooorritttieeesss is ok (the r letter)



Ppprioororitttieeesss is no ok (the r letter)



another example



invoice


will become



innvvooiccee


another example



Remittance Advice


will become



Rrremmmiitttaannncce Adddvvvice


Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same



the form of the letter does not matter, either cap or small will count as the same letter, Pip has 2 Ps and 1 I so it will become Piip



It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP



This is code-golf










share|improve this question



















  • 1




    How do we deal with capital letters?
    – xnor
    4 hours ago










  • Caps and small no difference, you can use either
    – asmgx
    4 hours ago







  • 1




    Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
    – Shieru Asakoto
    4 hours ago






  • 1




    @JonathanAllan will fix this now
    – asmgx
    11 mins ago






  • 2




    can we change the case of capitalised letters? e.g. Can Pip result in piip?
    – Jo King
    7 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Letters of the words want fairness



they decided to appear same number of times in a sentence equally



Example



Priorities


will become



Ppprrioooritttieeesss


each letter show 3 times as letter mostly used was i and it showed 3 times



it does not matter where you put the repeated letters as log as they next to a similar letter



means



Pppriooorritttieeesss is ok (the r letter)



Ppprioororitttieeesss is no ok (the r letter)



another example



invoice


will become



innvvooiccee


another example



Remittance Advice


will become



Rrremmmiitttaannncce Adddvvvice


Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same



the form of the letter does not matter, either cap or small will count as the same letter, Pip has 2 Ps and 1 I so it will become Piip



It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP



This is code-golf










share|improve this question















Letters of the words want fairness



they decided to appear same number of times in a sentence equally



Example



Priorities


will become



Ppprrioooritttieeesss


each letter show 3 times as letter mostly used was i and it showed 3 times



it does not matter where you put the repeated letters as log as they next to a similar letter



means



Pppriooorritttieeesss is ok (the r letter)



Ppprioororitttieeesss is no ok (the r letter)



another example



invoice


will become



innvvooiccee


another example



Remittance Advice


will become



Rrremmmiitttaannncce Adddvvvice


Space, comma, question mark, quotation, etc. are not letters letters are from (a-z both cap and small) , just once space is enough, and the order of the letters should remain the same



the form of the letter does not matter, either cap or small will count as the same letter, Pip has 2 Ps and 1 I so it will become Piip



It is case insensitive letters can be in any form, Piip=piip=piiP=PiiP



This is code-golf







code-golf word-puzzle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 mins ago

























asked 5 hours ago









asmgx

1156




1156







  • 1




    How do we deal with capital letters?
    – xnor
    4 hours ago










  • Caps and small no difference, you can use either
    – asmgx
    4 hours ago







  • 1




    Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
    – Shieru Asakoto
    4 hours ago






  • 1




    @JonathanAllan will fix this now
    – asmgx
    11 mins ago






  • 2




    can we change the case of capitalised letters? e.g. Can Pip result in piip?
    – Jo King
    7 mins ago












  • 1




    How do we deal with capital letters?
    – xnor
    4 hours ago










  • Caps and small no difference, you can use either
    – asmgx
    4 hours ago







  • 1




    Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
    – Shieru Asakoto
    4 hours ago






  • 1




    @JonathanAllan will fix this now
    – asmgx
    11 mins ago






  • 2




    can we change the case of capitalised letters? e.g. Can Pip result in piip?
    – Jo King
    7 mins ago







1




1




How do we deal with capital letters?
– xnor
4 hours ago




How do we deal with capital letters?
– xnor
4 hours ago












Caps and small no difference, you can use either
– asmgx
4 hours ago





Caps and small no difference, you can use either
– asmgx
4 hours ago





1




1




Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
– Shieru Asakoto
4 hours ago




Must the original (relative) order of the letters remain? If not an algorithm like the Perl answer would dominate.
– Shieru Asakoto
4 hours ago




1




1




@JonathanAllan will fix this now
– asmgx
11 mins ago




@JonathanAllan will fix this now
– asmgx
11 mins ago




2




2




can we change the case of capitalised letters? e.g. Can Pip result in piip?
– Jo King
7 mins ago




can we change the case of capitalised letters? e.g. Can Pip result in piip?
– Jo King
7 mins ago










4 Answers
4






active

oldest

votes

















up vote
3
down vote














05AB1E, 18 13 bytes



Case sensitive.



áÙSйs¢Zα>×.;


Try it online!



Explanation



á # keep only letters of input
Ù # remove duplicates
S # split to list of chars
Ð # triplicate
¹s¢ # count the occurrence of each unique letter in input
Zα # take abs with the max occurrence
> # increment
× # repeat each unique letter that many times
.; # replace the first occurrence of the letter in the input with this





share|improve this answer






















  • The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
    – Jonathan Allan
    5 mins ago










  • @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
    – Emigna
    1 min ago

















up vote
2
down vote














JavaScript (Node.js), 126 bytes





f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x


Try it online!



all lower or ALL UPPER only.



Explanation





f = x => // The function. `f=` is needed because we will
// use the function object as temporary storage
[...x].map(c => ( // - Iterate among each character...
f[c] = -~f[c], // - Add one to the character counter
f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
c // - Return back the character for the use in
// the next map function
), w = 0) // - The max counter
.map(c => // - Iterate again...
x = x.replace( // - Repeat the first appearance of
c, // - Each character
c.repeat( // - Needed number times
parseInt(c, 36) > 9 // - Additional constraint
? w - f[c] + 1 // - If this is letter, repeat
: 1 // - If not, stay as is
), // - That should've been clearly stated
f[c] = w // - And set the counter so that no further
// replacements are done on this character
) // - (w - f[c] + 1 = 1 in further iterations)
) && x // - Return the result





share|improve this answer





























    up vote
    2
    down vote














    J, 44 bytes



    #~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.


    Try it online!






    share|improve this answer





























      up vote
      1
      down vote














      Perl 6, 79 bytes





      ->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'


      Try it online!



      Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.



      Explanation:



      ->a # Anonymous code block that takes a mutable string 
      for 'a'..'z' # For each letter
      a.=subst( ) # Substitute
      $_, #The first occurrence of the letter with
      $_ x #The letter repeated
      a.comb(/<:Ll>/) The lowercase letters of the string
      .Bag.values.max # The count of the most common letter
      +1 # Plus 1
      -a.comb($_) # Minus the count of that letter already in the string





      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',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        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%2f173323%2fsame-number-letters%23new-answer', 'question_page');

        );

        Post as a guest






























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        3
        down vote














        05AB1E, 18 13 bytes



        Case sensitive.



        áÙSйs¢Zα>×.;


        Try it online!



        Explanation



        á # keep only letters of input
        Ù # remove duplicates
        S # split to list of chars
        Ð # triplicate
        ¹s¢ # count the occurrence of each unique letter in input
        Zα # take abs with the max occurrence
        > # increment
        × # repeat each unique letter that many times
        .; # replace the first occurrence of the letter in the input with this





        share|improve this answer






















        • The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
          – Jonathan Allan
          5 mins ago










        • @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
          – Emigna
          1 min ago














        up vote
        3
        down vote














        05AB1E, 18 13 bytes



        Case sensitive.



        áÙSйs¢Zα>×.;


        Try it online!



        Explanation



        á # keep only letters of input
        Ù # remove duplicates
        S # split to list of chars
        Ð # triplicate
        ¹s¢ # count the occurrence of each unique letter in input
        Zα # take abs with the max occurrence
        > # increment
        × # repeat each unique letter that many times
        .; # replace the first occurrence of the letter in the input with this





        share|improve this answer






















        • The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
          – Jonathan Allan
          5 mins ago










        • @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
          – Emigna
          1 min ago












        up vote
        3
        down vote










        up vote
        3
        down vote










        05AB1E, 18 13 bytes



        Case sensitive.



        áÙSйs¢Zα>×.;


        Try it online!



        Explanation



        á # keep only letters of input
        Ù # remove duplicates
        S # split to list of chars
        Ð # triplicate
        ¹s¢ # count the occurrence of each unique letter in input
        Zα # take abs with the max occurrence
        > # increment
        × # repeat each unique letter that many times
        .; # replace the first occurrence of the letter in the input with this





        share|improve this answer















        05AB1E, 18 13 bytes



        Case sensitive.



        áÙSйs¢Zα>×.;


        Try it online!



        Explanation



        á # keep only letters of input
        Ù # remove duplicates
        S # split to list of chars
        Ð # triplicate
        ¹s¢ # count the occurrence of each unique letter in input
        Zα # take abs with the max occurrence
        > # increment
        × # repeat each unique letter that many times
        .; # replace the first occurrence of the letter in the input with this






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 17 mins ago

























        answered 29 mins ago









        Emigna

        43.5k431131




        43.5k431131











        • The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
          – Jonathan Allan
          5 mins ago










        • @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
          – Emigna
          1 min ago
















        • The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
          – Jonathan Allan
          5 mins ago










        • @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
          – Emigna
          1 min ago















        The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
        – Jonathan Allan
        5 mins ago




        The input is meant to be able to contain mixed case, then be treated case insensitively e.g. Pip -> Ppii; so this does not currently fit spec. However as Jo king just asked we do not know if ppii or PPII would be acceptable...
        – Jonathan Allan
        5 mins ago












        @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
        – Emigna
        1 min ago




        @JonathanAllan: Yeah, I'm following the comments to see how the specs are finalized.
        – Emigna
        1 min ago










        up vote
        2
        down vote














        JavaScript (Node.js), 126 bytes





        f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x


        Try it online!



        all lower or ALL UPPER only.



        Explanation





        f = x => // The function. `f=` is needed because we will
        // use the function object as temporary storage
        [...x].map(c => ( // - Iterate among each character...
        f[c] = -~f[c], // - Add one to the character counter
        f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
        c // - Return back the character for the use in
        // the next map function
        ), w = 0) // - The max counter
        .map(c => // - Iterate again...
        x = x.replace( // - Repeat the first appearance of
        c, // - Each character
        c.repeat( // - Needed number times
        parseInt(c, 36) > 9 // - Additional constraint
        ? w - f[c] + 1 // - If this is letter, repeat
        : 1 // - If not, stay as is
        ), // - That should've been clearly stated
        f[c] = w // - And set the counter so that no further
        // replacements are done on this character
        ) // - (w - f[c] + 1 = 1 in further iterations)
        ) && x // - Return the result





        share|improve this answer


























          up vote
          2
          down vote














          JavaScript (Node.js), 126 bytes





          f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x


          Try it online!



          all lower or ALL UPPER only.



          Explanation





          f = x => // The function. `f=` is needed because we will
          // use the function object as temporary storage
          [...x].map(c => ( // - Iterate among each character...
          f[c] = -~f[c], // - Add one to the character counter
          f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
          c // - Return back the character for the use in
          // the next map function
          ), w = 0) // - The max counter
          .map(c => // - Iterate again...
          x = x.replace( // - Repeat the first appearance of
          c, // - Each character
          c.repeat( // - Needed number times
          parseInt(c, 36) > 9 // - Additional constraint
          ? w - f[c] + 1 // - If this is letter, repeat
          : 1 // - If not, stay as is
          ), // - That should've been clearly stated
          f[c] = w // - And set the counter so that no further
          // replacements are done on this character
          ) // - (w - f[c] + 1 = 1 in further iterations)
          ) && x // - Return the result





          share|improve this answer
























            up vote
            2
            down vote










            up vote
            2
            down vote










            JavaScript (Node.js), 126 bytes





            f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x


            Try it online!



            all lower or ALL UPPER only.



            Explanation





            f = x => // The function. `f=` is needed because we will
            // use the function object as temporary storage
            [...x].map(c => ( // - Iterate among each character...
            f[c] = -~f[c], // - Add one to the character counter
            f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
            c // - Return back the character for the use in
            // the next map function
            ), w = 0) // - The max counter
            .map(c => // - Iterate again...
            x = x.replace( // - Repeat the first appearance of
            c, // - Each character
            c.repeat( // - Needed number times
            parseInt(c, 36) > 9 // - Additional constraint
            ? w - f[c] + 1 // - If this is letter, repeat
            : 1 // - If not, stay as is
            ), // - That should've been clearly stated
            f[c] = w // - And set the counter so that no further
            // replacements are done on this character
            ) // - (w - f[c] + 1 = 1 in further iterations)
            ) && x // - Return the result





            share|improve this answer















            JavaScript (Node.js), 126 bytes





            f=x=>[...x].map(c=>(f[c]=-~f[c],f[c]>w?w=f[c]:w,c),w=0).map(c=>x=x.replace(c,c.repeat(parseInt(c,36)>9?w-f[c]+1:1),f[c]=w))&&x


            Try it online!



            all lower or ALL UPPER only.



            Explanation





            f = x => // The function. `f=` is needed because we will
            // use the function object as temporary storage
            [...x].map(c => ( // - Iterate among each character...
            f[c] = -~f[c], // - Add one to the character counter
            f[c] > w ? w = f[c] : w, // - Update the maximum count if necessary
            c // - Return back the character for the use in
            // the next map function
            ), w = 0) // - The max counter
            .map(c => // - Iterate again...
            x = x.replace( // - Repeat the first appearance of
            c, // - Each character
            c.repeat( // - Needed number times
            parseInt(c, 36) > 9 // - Additional constraint
            ? w - f[c] + 1 // - If this is letter, repeat
            : 1 // - If not, stay as is
            ), // - That should've been clearly stated
            f[c] = w // - And set the counter so that no further
            // replacements are done on this character
            ) // - (w - f[c] + 1 = 1 in further iterations)
            ) && x // - Return the result






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 45 mins ago

























            answered 4 hours ago









            Shieru Asakoto

            1,690311




            1,690311




















                up vote
                2
                down vote














                J, 44 bytes



                #~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.


                Try it online!






                share|improve this answer


























                  up vote
                  2
                  down vote














                  J, 44 bytes



                  #~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.


                  Try it online!






                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    J, 44 bytes



                    #~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.


                    Try it online!






                    share|improve this answer















                    J, 44 bytes



                    #~1+(</"1@=*a)+/@(*>./-])#/.~*a=.1='`z'I.~.


                    Try it online!







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 15 mins ago

























                    answered 3 hours ago









                    FrownyFrog

                    2,1671518




                    2,1671518




















                        up vote
                        1
                        down vote














                        Perl 6, 79 bytes





                        ->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'


                        Try it online!



                        Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.



                        Explanation:



                        ->a # Anonymous code block that takes a mutable string 
                        for 'a'..'z' # For each letter
                        a.=subst( ) # Substitute
                        $_, #The first occurrence of the letter with
                        $_ x #The letter repeated
                        a.comb(/<:Ll>/) The lowercase letters of the string
                        .Bag.values.max # The count of the most common letter
                        +1 # Plus 1
                        -a.comb($_) # Minus the count of that letter already in the string





                        share|improve this answer


























                          up vote
                          1
                          down vote














                          Perl 6, 79 bytes





                          ->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'


                          Try it online!



                          Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.



                          Explanation:



                          ->a # Anonymous code block that takes a mutable string 
                          for 'a'..'z' # For each letter
                          a.=subst( ) # Substitute
                          $_, #The first occurrence of the letter with
                          $_ x #The letter repeated
                          a.comb(/<:Ll>/) The lowercase letters of the string
                          .Bag.values.max # The count of the most common letter
                          +1 # Plus 1
                          -a.comb($_) # Minus the count of that letter already in the string





                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote










                            Perl 6, 79 bytes





                            ->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'


                            Try it online!



                            Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.



                            Explanation:



                            ->a # Anonymous code block that takes a mutable string 
                            for 'a'..'z' # For each letter
                            a.=subst( ) # Substitute
                            $_, #The first occurrence of the letter with
                            $_ x #The letter repeated
                            a.comb(/<:Ll>/) The lowercase letters of the string
                            .Bag.values.max # The count of the most common letter
                            +1 # Plus 1
                            -a.comb($_) # Minus the count of that letter already in the string





                            share|improve this answer















                            Perl 6, 79 bytes





                            ->aa.=subst($_,$_ x a.comb(/<:Ll>/).Bag.values.max+1-a.comb($_))for 'a'..'z'


                            Try it online!



                            Takes a mutable string and edits it in place. This makes no distinction between case, so input should be either all upper or all lower case. Oof, this feels like it could be shorter.



                            Explanation:



                            ->a # Anonymous code block that takes a mutable string 
                            for 'a'..'z' # For each letter
                            a.=subst( ) # Substitute
                            $_, #The first occurrence of the letter with
                            $_ x #The letter repeated
                            a.comb(/<:Ll>/) The lowercase letters of the string
                            .Bag.values.max # The count of the most common letter
                            +1 # Plus 1
                            -a.comb($_) # Minus the count of that letter already in the string






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 19 mins ago

























                            answered 4 hours ago









                            Jo King

                            16.8k24193




                            16.8k24193



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173323%2fsame-number-letters%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                Installing NextGIS Connect into QGIS 3?

                                One-line joke