Longest Repeating Subsequence of a Single Digit

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











up vote
2
down vote

favorite












Challenge:



Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer).



An example:



Input: 7888885466662716666

The longest subsequence of a single digit would be 88888 (7[88888]5466662716666) with a length of 5. However, this subsequence only occurs once in the integer.

Instead, the result for input 7888885466662716666 should be 6666 (78888854[6666]271[6666]), since it occurs (at least) twice.



Challenge rules:



  • Length of the subsequences takes priority over the amount of times it occurs. (I.e. with input 8888858888866656665666, we output 88888 ([88888]5[88888]66656665666; length 5, occurs twice), and not 666 (88888588888[666]5[666]5[666]; length 3, occurs thrice).

  • If the length of multiple subsequences are equal, we output the one with the largest occurrence-count. I.e. with input 3331113331119111, we output 111 (333[111]333[111]9[111]; length 3, occurs thrice), and not 333 ([333]111[333]1119111; length 3 as well, but occurs twice)

  • If the occurrence-count and length of multiple subsequences are equal, you can output either of them, or all (in any order). I.e. with input 777333777333, the possible outputs are: 777; 333; [777, 333]; or [333, 777].

  • The subsequence must have boundaries of other digits (or the start/end of the integer). I.e. with input 122222233433 the result is 33 (1222222[33]4[33]; length 2, occurs twice) and not 222 (1[222][222]33433, length 3, occurs twice with both invalid).

    • This applies to all numbers that are counted towards the occurrence-counter. I.e. with input 811774177781382 the result is 8 ([8]117741777[8]13[8]2; length 1, occurs thrice) and not 77 (811[77]41[77]781382 / 811[77]417[77]81382; length 2, occurs twice with one invalid) nor 1 (8[1][1]774[1]7778[1]382; length 1, occurs four times with two invalid).


  • You can assume the input won't contain any digits 0 (it will match [1-9]+). (This is to avoid having to deal with test cases like 10002000 that should output 000, where most languages would output 0 by default.)

  • You can assume the input will always contain at least one valid output.

  • I/O are both flexible. Can be a list/array/stream of digits/bytes/characters or as string instead of a single integer.

General rules:



  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code.

  • Also, adding an explanation for your answer is highly recommended.

Test cases:



Input: 7888885466662716666 / [7,8,8,8,8,8,5,4,6,6,6,6,2,7,1,6,6,6,6]
Output: 6666 / [6,6,6,6]

Input: 3331113331119111 / [3,3,3,1,1,1,3,3,3,1,1,1,9,1,1,1]
Output: 111 / [1,1,1]

Input: 777333777333 / [7,7,7,3,3,3,7,7,7,3,3,3]
Possible outputs: 777; 333; [777,333]; [333;777] / [7,7,7]; [3,3,3]; [[7,7,7],[3,3,3]]; [[3,3,3],[7,7,7]]

Input: 122222233433 / [1,2,2,2,2,2,2,3,3,4,3,3]
Output: 33 / [3,3]

Input: 811774177781382 / [8,1,1,7,7,4,1,7,7,7,8,1,3,8,2]
Output: 8 / [8]

Input: 555153333551 / [5,5,5,1,5,3,3,3,3,5,5,1]
Output: 1 / [1]

Input: 12321 / [1,2,3,2,1]
Possible outputs: 1; 2; [1,2]; [2,1] / [1]; [2]; [[1],[2]]; [[2],[1]]

Input: 944949949494999494 / [9,4,4,9,4,9,9,4,9,4,9,4,9,9,9,4,9,4]
Output: 4 / [4]

Input: 8888858888866656665666 / [8,8,8,8,8,5,8,8,8,8,8,6,6,6,5,6,6,6,5,6,6,6]
Output: 88888 / [8,8,8,8,8]









share|improve this question



















  • 1




    Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
    – Mr. Xcoder
    12 mins ago










  • @Mr.Xcoder Added, thanks.
    – Kevin Cruijssen
    8 mins ago














up vote
2
down vote

favorite












Challenge:



Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer).



An example:



Input: 7888885466662716666

The longest subsequence of a single digit would be 88888 (7[88888]5466662716666) with a length of 5. However, this subsequence only occurs once in the integer.

Instead, the result for input 7888885466662716666 should be 6666 (78888854[6666]271[6666]), since it occurs (at least) twice.



Challenge rules:



  • Length of the subsequences takes priority over the amount of times it occurs. (I.e. with input 8888858888866656665666, we output 88888 ([88888]5[88888]66656665666; length 5, occurs twice), and not 666 (88888588888[666]5[666]5[666]; length 3, occurs thrice).

  • If the length of multiple subsequences are equal, we output the one with the largest occurrence-count. I.e. with input 3331113331119111, we output 111 (333[111]333[111]9[111]; length 3, occurs thrice), and not 333 ([333]111[333]1119111; length 3 as well, but occurs twice)

  • If the occurrence-count and length of multiple subsequences are equal, you can output either of them, or all (in any order). I.e. with input 777333777333, the possible outputs are: 777; 333; [777, 333]; or [333, 777].

  • The subsequence must have boundaries of other digits (or the start/end of the integer). I.e. with input 122222233433 the result is 33 (1222222[33]4[33]; length 2, occurs twice) and not 222 (1[222][222]33433, length 3, occurs twice with both invalid).

    • This applies to all numbers that are counted towards the occurrence-counter. I.e. with input 811774177781382 the result is 8 ([8]117741777[8]13[8]2; length 1, occurs thrice) and not 77 (811[77]41[77]781382 / 811[77]417[77]81382; length 2, occurs twice with one invalid) nor 1 (8[1][1]774[1]7778[1]382; length 1, occurs four times with two invalid).


  • You can assume the input won't contain any digits 0 (it will match [1-9]+). (This is to avoid having to deal with test cases like 10002000 that should output 000, where most languages would output 0 by default.)

  • You can assume the input will always contain at least one valid output.

  • I/O are both flexible. Can be a list/array/stream of digits/bytes/characters or as string instead of a single integer.

General rules:



  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code.

  • Also, adding an explanation for your answer is highly recommended.

Test cases:



Input: 7888885466662716666 / [7,8,8,8,8,8,5,4,6,6,6,6,2,7,1,6,6,6,6]
Output: 6666 / [6,6,6,6]

Input: 3331113331119111 / [3,3,3,1,1,1,3,3,3,1,1,1,9,1,1,1]
Output: 111 / [1,1,1]

Input: 777333777333 / [7,7,7,3,3,3,7,7,7,3,3,3]
Possible outputs: 777; 333; [777,333]; [333;777] / [7,7,7]; [3,3,3]; [[7,7,7],[3,3,3]]; [[3,3,3],[7,7,7]]

Input: 122222233433 / [1,2,2,2,2,2,2,3,3,4,3,3]
Output: 33 / [3,3]

Input: 811774177781382 / [8,1,1,7,7,4,1,7,7,7,8,1,3,8,2]
Output: 8 / [8]

Input: 555153333551 / [5,5,5,1,5,3,3,3,3,5,5,1]
Output: 1 / [1]

Input: 12321 / [1,2,3,2,1]
Possible outputs: 1; 2; [1,2]; [2,1] / [1]; [2]; [[1],[2]]; [[2],[1]]

Input: 944949949494999494 / [9,4,4,9,4,9,9,4,9,4,9,4,9,9,9,4,9,4]
Output: 4 / [4]

Input: 8888858888866656665666 / [8,8,8,8,8,5,8,8,8,8,8,6,6,6,5,6,6,6,5,6,6,6]
Output: 88888 / [8,8,8,8,8]









share|improve this question



















  • 1




    Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
    – Mr. Xcoder
    12 mins ago










  • @Mr.Xcoder Added, thanks.
    – Kevin Cruijssen
    8 mins ago












up vote
2
down vote

favorite









up vote
2
down vote

favorite











Challenge:



Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer).



An example:



Input: 7888885466662716666

The longest subsequence of a single digit would be 88888 (7[88888]5466662716666) with a length of 5. However, this subsequence only occurs once in the integer.

Instead, the result for input 7888885466662716666 should be 6666 (78888854[6666]271[6666]), since it occurs (at least) twice.



Challenge rules:



  • Length of the subsequences takes priority over the amount of times it occurs. (I.e. with input 8888858888866656665666, we output 88888 ([88888]5[88888]66656665666; length 5, occurs twice), and not 666 (88888588888[666]5[666]5[666]; length 3, occurs thrice).

  • If the length of multiple subsequences are equal, we output the one with the largest occurrence-count. I.e. with input 3331113331119111, we output 111 (333[111]333[111]9[111]; length 3, occurs thrice), and not 333 ([333]111[333]1119111; length 3 as well, but occurs twice)

  • If the occurrence-count and length of multiple subsequences are equal, you can output either of them, or all (in any order). I.e. with input 777333777333, the possible outputs are: 777; 333; [777, 333]; or [333, 777].

  • The subsequence must have boundaries of other digits (or the start/end of the integer). I.e. with input 122222233433 the result is 33 (1222222[33]4[33]; length 2, occurs twice) and not 222 (1[222][222]33433, length 3, occurs twice with both invalid).

    • This applies to all numbers that are counted towards the occurrence-counter. I.e. with input 811774177781382 the result is 8 ([8]117741777[8]13[8]2; length 1, occurs thrice) and not 77 (811[77]41[77]781382 / 811[77]417[77]81382; length 2, occurs twice with one invalid) nor 1 (8[1][1]774[1]7778[1]382; length 1, occurs four times with two invalid).


  • You can assume the input won't contain any digits 0 (it will match [1-9]+). (This is to avoid having to deal with test cases like 10002000 that should output 000, where most languages would output 0 by default.)

  • You can assume the input will always contain at least one valid output.

  • I/O are both flexible. Can be a list/array/stream of digits/bytes/characters or as string instead of a single integer.

General rules:



  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code.

  • Also, adding an explanation for your answer is highly recommended.

Test cases:



Input: 7888885466662716666 / [7,8,8,8,8,8,5,4,6,6,6,6,2,7,1,6,6,6,6]
Output: 6666 / [6,6,6,6]

Input: 3331113331119111 / [3,3,3,1,1,1,3,3,3,1,1,1,9,1,1,1]
Output: 111 / [1,1,1]

Input: 777333777333 / [7,7,7,3,3,3,7,7,7,3,3,3]
Possible outputs: 777; 333; [777,333]; [333;777] / [7,7,7]; [3,3,3]; [[7,7,7],[3,3,3]]; [[3,3,3],[7,7,7]]

Input: 122222233433 / [1,2,2,2,2,2,2,3,3,4,3,3]
Output: 33 / [3,3]

Input: 811774177781382 / [8,1,1,7,7,4,1,7,7,7,8,1,3,8,2]
Output: 8 / [8]

Input: 555153333551 / [5,5,5,1,5,3,3,3,3,5,5,1]
Output: 1 / [1]

Input: 12321 / [1,2,3,2,1]
Possible outputs: 1; 2; [1,2]; [2,1] / [1]; [2]; [[1],[2]]; [[2],[1]]

Input: 944949949494999494 / [9,4,4,9,4,9,9,4,9,4,9,4,9,9,9,4,9,4]
Output: 4 / [4]

Input: 8888858888866656665666 / [8,8,8,8,8,5,8,8,8,8,8,6,6,6,5,6,6,6,5,6,6,6]
Output: 88888 / [8,8,8,8,8]









share|improve this question















Challenge:



Given a positive integer, output the longest single-digit subsequence that occurs at least twice, AND has boundaries of another digit (or the start/end of the integer).



An example:



Input: 7888885466662716666

The longest subsequence of a single digit would be 88888 (7[88888]5466662716666) with a length of 5. However, this subsequence only occurs once in the integer.

Instead, the result for input 7888885466662716666 should be 6666 (78888854[6666]271[6666]), since it occurs (at least) twice.



Challenge rules:



  • Length of the subsequences takes priority over the amount of times it occurs. (I.e. with input 8888858888866656665666, we output 88888 ([88888]5[88888]66656665666; length 5, occurs twice), and not 666 (88888588888[666]5[666]5[666]; length 3, occurs thrice).

  • If the length of multiple subsequences are equal, we output the one with the largest occurrence-count. I.e. with input 3331113331119111, we output 111 (333[111]333[111]9[111]; length 3, occurs thrice), and not 333 ([333]111[333]1119111; length 3 as well, but occurs twice)

  • If the occurrence-count and length of multiple subsequences are equal, you can output either of them, or all (in any order). I.e. with input 777333777333, the possible outputs are: 777; 333; [777, 333]; or [333, 777].

  • The subsequence must have boundaries of other digits (or the start/end of the integer). I.e. with input 122222233433 the result is 33 (1222222[33]4[33]; length 2, occurs twice) and not 222 (1[222][222]33433, length 3, occurs twice with both invalid).

    • This applies to all numbers that are counted towards the occurrence-counter. I.e. with input 811774177781382 the result is 8 ([8]117741777[8]13[8]2; length 1, occurs thrice) and not 77 (811[77]41[77]781382 / 811[77]417[77]81382; length 2, occurs twice with one invalid) nor 1 (8[1][1]774[1]7778[1]382; length 1, occurs four times with two invalid).


  • You can assume the input won't contain any digits 0 (it will match [1-9]+). (This is to avoid having to deal with test cases like 10002000 that should output 000, where most languages would output 0 by default.)

  • You can assume the input will always contain at least one valid output.

  • I/O are both flexible. Can be a list/array/stream of digits/bytes/characters or as string instead of a single integer.

General rules:



  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code.

  • Also, adding an explanation for your answer is highly recommended.

Test cases:



Input: 7888885466662716666 / [7,8,8,8,8,8,5,4,6,6,6,6,2,7,1,6,6,6,6]
Output: 6666 / [6,6,6,6]

Input: 3331113331119111 / [3,3,3,1,1,1,3,3,3,1,1,1,9,1,1,1]
Output: 111 / [1,1,1]

Input: 777333777333 / [7,7,7,3,3,3,7,7,7,3,3,3]
Possible outputs: 777; 333; [777,333]; [333;777] / [7,7,7]; [3,3,3]; [[7,7,7],[3,3,3]]; [[3,3,3],[7,7,7]]

Input: 122222233433 / [1,2,2,2,2,2,2,3,3,4,3,3]
Output: 33 / [3,3]

Input: 811774177781382 / [8,1,1,7,7,4,1,7,7,7,8,1,3,8,2]
Output: 8 / [8]

Input: 555153333551 / [5,5,5,1,5,3,3,3,3,5,5,1]
Output: 1 / [1]

Input: 12321 / [1,2,3,2,1]
Possible outputs: 1; 2; [1,2]; [2,1] / [1]; [2]; [[1],[2]]; [[2],[1]]

Input: 944949949494999494 / [9,4,4,9,4,9,9,4,9,4,9,4,9,9,9,4,9,4]
Output: 4 / [4]

Input: 8888858888866656665666 / [8,8,8,8,8,5,8,8,8,8,8,6,6,6,5,6,6,6,5,6,6,6]
Output: 88888 / [8,8,8,8,8]






code-golf number integer counting subsequence






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 mins ago

























asked 56 mins ago









Kevin Cruijssen

30.1k552165




30.1k552165







  • 1




    Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
    – Mr. Xcoder
    12 mins ago










  • @Mr.Xcoder Added, thanks.
    – Kevin Cruijssen
    8 mins ago












  • 1




    Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
    – Mr. Xcoder
    12 mins ago










  • @Mr.Xcoder Added, thanks.
    – Kevin Cruijssen
    8 mins ago







1




1




Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
– Mr. Xcoder
12 mins ago




Suggested test case: 8888858888866656665666. If I interpreted the challenge correctly, both the Brachylog and 05AB1E solutions fail.
– Mr. Xcoder
12 mins ago












@Mr.Xcoder Added, thanks.
– Kevin Cruijssen
8 mins ago




@Mr.Xcoder Added, thanks.
– Kevin Cruijssen
8 mins ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote














Retina, 56 bytes



L`(.)1*
O`
L$m`^(.+)(¶1)+$
$#2;$1
N`
.+;

N$`
$.&
-1G`


Try it online! Link includes test cases. Explanation:



L`(.)1*


List all the maximally repeated digit subsequences.



O`


Sort the list into order.



L$m`^(.+)(¶1)+$
$#2;$1


List all the multiple subsequences with their "count".



N`


Sort in ascending order of count.



.+;


Delete the counts.



N$`
$.&


Sort in ascending order of length. (Where lengths are equal, the previous order due to count is preserved.)



-1G`


Keep the last i.e. longest value.






share|improve this answer



























    up vote
    2
    down vote














    Jelly, 12 bytes



    Œgœ-Q$LÐṀÆṃ'


    Try it online!



    Previous version – 14 bytes



    ŒgŒQ¬TịƲLÐṀÆṃ'


    Try it online!



    How it works?



    Œgœ-Q$LÐṀÆṃ' – Full program. Receives a list of digits as input.
    Œg – Group equal adjacent values.
    œ-Q$ – Multiset difference with itself deduplicate.
    LÐṀ – Keep those that are maximal by length.
    Æṃ' – Mode. Returns the most common element(s).
    -------------------------------------------------------------------------
    ŒgŒQ¬TịƲLÐṀÆṃ' – Full program. Receives a list of digits as input.
    Œg – Group equal adjacent values.
    ŒQ – Distinct sieve. Replace the first occurrences of each value by 1.
    and the rest by 0. [1,2,3,2,3,2,5]Ã…Â’Q -> [1,1,1,0,0,0,1]
    ¬T – Negate and find the truthy indices.
    ịƲ – Then index in the initial list of groups.
    – This discards the groups that only occur once.
    LÐṀ – Find all those which are maximal by length.
    Æṃ' – And take the mode.





    share|improve this answer





























      up vote
      1
      down vote














      Python 2, 123 120 bytes





      import re
      def f(s):r=re.findall(r'(d)(1*)',s);c=r.count;print max((len(a+b)*(c((a,b))>1),c((a,b)),a+b)for a,b in r)[2]


      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',
        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%2f172295%2flongest-repeating-subsequence-of-a-single-digit%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        2
        down vote














        Retina, 56 bytes



        L`(.)1*
        O`
        L$m`^(.+)(¶1)+$
        $#2;$1
        N`
        .+;

        N$`
        $.&
        -1G`


        Try it online! Link includes test cases. Explanation:



        L`(.)1*


        List all the maximally repeated digit subsequences.



        O`


        Sort the list into order.



        L$m`^(.+)(¶1)+$
        $#2;$1


        List all the multiple subsequences with their "count".



        N`


        Sort in ascending order of count.



        .+;


        Delete the counts.



        N$`
        $.&


        Sort in ascending order of length. (Where lengths are equal, the previous order due to count is preserved.)



        -1G`


        Keep the last i.e. longest value.






        share|improve this answer
























          up vote
          2
          down vote














          Retina, 56 bytes



          L`(.)1*
          O`
          L$m`^(.+)(¶1)+$
          $#2;$1
          N`
          .+;

          N$`
          $.&
          -1G`


          Try it online! Link includes test cases. Explanation:



          L`(.)1*


          List all the maximally repeated digit subsequences.



          O`


          Sort the list into order.



          L$m`^(.+)(¶1)+$
          $#2;$1


          List all the multiple subsequences with their "count".



          N`


          Sort in ascending order of count.



          .+;


          Delete the counts.



          N$`
          $.&


          Sort in ascending order of length. (Where lengths are equal, the previous order due to count is preserved.)



          -1G`


          Keep the last i.e. longest value.






          share|improve this answer






















            up vote
            2
            down vote










            up vote
            2
            down vote










            Retina, 56 bytes



            L`(.)1*
            O`
            L$m`^(.+)(¶1)+$
            $#2;$1
            N`
            .+;

            N$`
            $.&
            -1G`


            Try it online! Link includes test cases. Explanation:



            L`(.)1*


            List all the maximally repeated digit subsequences.



            O`


            Sort the list into order.



            L$m`^(.+)(¶1)+$
            $#2;$1


            List all the multiple subsequences with their "count".



            N`


            Sort in ascending order of count.



            .+;


            Delete the counts.



            N$`
            $.&


            Sort in ascending order of length. (Where lengths are equal, the previous order due to count is preserved.)



            -1G`


            Keep the last i.e. longest value.






            share|improve this answer













            Retina, 56 bytes



            L`(.)1*
            O`
            L$m`^(.+)(¶1)+$
            $#2;$1
            N`
            .+;

            N$`
            $.&
            -1G`


            Try it online! Link includes test cases. Explanation:



            L`(.)1*


            List all the maximally repeated digit subsequences.



            O`


            Sort the list into order.



            L$m`^(.+)(¶1)+$
            $#2;$1


            List all the multiple subsequences with their "count".



            N`


            Sort in ascending order of count.



            .+;


            Delete the counts.



            N$`
            $.&


            Sort in ascending order of length. (Where lengths are equal, the previous order due to count is preserved.)



            -1G`


            Keep the last i.e. longest value.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 35 mins ago









            Neil

            75.3k744170




            75.3k744170




















                up vote
                2
                down vote














                Jelly, 12 bytes



                Œgœ-Q$LÐṀÆṃ'


                Try it online!



                Previous version – 14 bytes



                ŒgŒQ¬TịƲLÐṀÆṃ'


                Try it online!



                How it works?



                Œgœ-Q$LÐṀÆṃ' – Full program. Receives a list of digits as input.
                Œg – Group equal adjacent values.
                œ-Q$ – Multiset difference with itself deduplicate.
                LÐṀ – Keep those that are maximal by length.
                Æṃ' – Mode. Returns the most common element(s).
                -------------------------------------------------------------------------
                ŒgŒQ¬TịƲLÐṀÆṃ' – Full program. Receives a list of digits as input.
                Œg – Group equal adjacent values.
                ŒQ – Distinct sieve. Replace the first occurrences of each value by 1.
                and the rest by 0. [1,2,3,2,3,2,5]Ã…Â’Q -> [1,1,1,0,0,0,1]
                ¬T – Negate and find the truthy indices.
                ịƲ – Then index in the initial list of groups.
                – This discards the groups that only occur once.
                LÐṀ – Find all those which are maximal by length.
                Æṃ' – And take the mode.





                share|improve this answer


























                  up vote
                  2
                  down vote














                  Jelly, 12 bytes



                  Œgœ-Q$LÐṀÆṃ'


                  Try it online!



                  Previous version – 14 bytes



                  ŒgŒQ¬TịƲLÐṀÆṃ'


                  Try it online!



                  How it works?



                  Œgœ-Q$LÐṀÆṃ' – Full program. Receives a list of digits as input.
                  Œg – Group equal adjacent values.
                  œ-Q$ – Multiset difference with itself deduplicate.
                  LÐṀ – Keep those that are maximal by length.
                  Æṃ' – Mode. Returns the most common element(s).
                  -------------------------------------------------------------------------
                  ŒgŒQ¬TịƲLÐṀÆṃ' – Full program. Receives a list of digits as input.
                  Œg – Group equal adjacent values.
                  ŒQ – Distinct sieve. Replace the first occurrences of each value by 1.
                  and the rest by 0. [1,2,3,2,3,2,5]Ã…Â’Q -> [1,1,1,0,0,0,1]
                  ¬T – Negate and find the truthy indices.
                  ịƲ – Then index in the initial list of groups.
                  – This discards the groups that only occur once.
                  LÐṀ – Find all those which are maximal by length.
                  Æṃ' – And take the mode.





                  share|improve this answer
























                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote










                    Jelly, 12 bytes



                    Œgœ-Q$LÐṀÆṃ'


                    Try it online!



                    Previous version – 14 bytes



                    ŒgŒQ¬TịƲLÐṀÆṃ'


                    Try it online!



                    How it works?



                    Œgœ-Q$LÐṀÆṃ' – Full program. Receives a list of digits as input.
                    Œg – Group equal adjacent values.
                    œ-Q$ – Multiset difference with itself deduplicate.
                    LÐṀ – Keep those that are maximal by length.
                    Æṃ' – Mode. Returns the most common element(s).
                    -------------------------------------------------------------------------
                    ŒgŒQ¬TịƲLÐṀÆṃ' – Full program. Receives a list of digits as input.
                    Œg – Group equal adjacent values.
                    ŒQ – Distinct sieve. Replace the first occurrences of each value by 1.
                    and the rest by 0. [1,2,3,2,3,2,5]Ã…Â’Q -> [1,1,1,0,0,0,1]
                    ¬T – Negate and find the truthy indices.
                    ịƲ – Then index in the initial list of groups.
                    – This discards the groups that only occur once.
                    LÐṀ – Find all those which are maximal by length.
                    Æṃ' – And take the mode.





                    share|improve this answer















                    Jelly, 12 bytes



                    Œgœ-Q$LÐṀÆṃ'


                    Try it online!



                    Previous version – 14 bytes



                    ŒgŒQ¬TịƲLÐṀÆṃ'


                    Try it online!



                    How it works?



                    Œgœ-Q$LÐṀÆṃ' – Full program. Receives a list of digits as input.
                    Œg – Group equal adjacent values.
                    œ-Q$ – Multiset difference with itself deduplicate.
                    LÐṀ – Keep those that are maximal by length.
                    Æṃ' – Mode. Returns the most common element(s).
                    -------------------------------------------------------------------------
                    ŒgŒQ¬TịƲLÐṀÆṃ' – Full program. Receives a list of digits as input.
                    Œg – Group equal adjacent values.
                    ŒQ – Distinct sieve. Replace the first occurrences of each value by 1.
                    and the rest by 0. [1,2,3,2,3,2,5]Ã…Â’Q -> [1,1,1,0,0,0,1]
                    ¬T – Negate and find the truthy indices.
                    ịƲ – Then index in the initial list of groups.
                    – This discards the groups that only occur once.
                    LÐṀ – Find all those which are maximal by length.
                    Æṃ' – And take the mode.






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 3 mins ago

























                    answered 25 mins ago









                    Mr. Xcoder

                    30.4k758193




                    30.4k758193




















                        up vote
                        1
                        down vote














                        Python 2, 123 120 bytes





                        import re
                        def f(s):r=re.findall(r'(d)(1*)',s);c=r.count;print max((len(a+b)*(c((a,b))>1),c((a,b)),a+b)for a,b in r)[2]


                        Try it online!






                        share|improve this answer


























                          up vote
                          1
                          down vote














                          Python 2, 123 120 bytes





                          import re
                          def f(s):r=re.findall(r'(d)(1*)',s);c=r.count;print max((len(a+b)*(c((a,b))>1),c((a,b)),a+b)for a,b in r)[2]


                          Try it online!






                          share|improve this answer
























                            up vote
                            1
                            down vote










                            up vote
                            1
                            down vote










                            Python 2, 123 120 bytes





                            import re
                            def f(s):r=re.findall(r'(d)(1*)',s);c=r.count;print max((len(a+b)*(c((a,b))>1),c((a,b)),a+b)for a,b in r)[2]


                            Try it online!






                            share|improve this answer















                            Python 2, 123 120 bytes





                            import re
                            def f(s):r=re.findall(r'(d)(1*)',s);c=r.count;print max((len(a+b)*(c((a,b))>1),c((a,b)),a+b)for a,b in r)[2]


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 16 mins ago

























                            answered 36 mins ago









                            TFeld

                            11.5k2833




                            11.5k2833



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172295%2flongest-repeating-subsequence-of-a-single-digit%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Comments

                                Popular posts from this blog

                                What does second last employer means? [closed]

                                List of Gilmore Girls characters

                                Confectionery