Longest Repeating Subsequence of a Single Digit
Clash 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 output88888
([88888]5[88888]66656665666
; length 5, occurs twice), and not666
(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 output111
(333[111]333[111]9[111]
; length 3, occurs thrice), and not333
([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 is33
(1222222[33]4[33]
; length 2, occurs twice) and not222
(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 is8
([8]117741777[8]13[8]2
; length 1, occurs thrice) and not77
(811[77]41[77]781382
/811[77]417[77]81382
; length 2, occurs twice with one invalid) nor1
(8[1][1]774[1]7778[1]382
; length 1, occurs four times with two invalid).
- This applies to all numbers that are counted towards the occurrence-counter. I.e. with input
- 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 like10002000
that should output000
, where most languages would output0
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
add a comment |Â
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 output88888
([88888]5[88888]66656665666
; length 5, occurs twice), and not666
(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 output111
(333[111]333[111]9[111]
; length 3, occurs thrice), and not333
([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 is33
(1222222[33]4[33]
; length 2, occurs twice) and not222
(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 is8
([8]117741777[8]13[8]2
; length 1, occurs thrice) and not77
(811[77]41[77]781382
/811[77]417[77]81382
; length 2, occurs twice with one invalid) nor1
(8[1][1]774[1]7778[1]382
; length 1, occurs four times with two invalid).
- This applies to all numbers that are counted towards the occurrence-counter. I.e. with input
- 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 like10002000
that should output000
, where most languages would output0
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
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
add a comment |Â
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 output88888
([88888]5[88888]66656665666
; length 5, occurs twice), and not666
(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 output111
(333[111]333[111]9[111]
; length 3, occurs thrice), and not333
([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 is33
(1222222[33]4[33]
; length 2, occurs twice) and not222
(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 is8
([8]117741777[8]13[8]2
; length 1, occurs thrice) and not77
(811[77]41[77]781382
/811[77]417[77]81382
; length 2, occurs twice with one invalid) nor1
(8[1][1]774[1]7778[1]382
; length 1, occurs four times with two invalid).
- This applies to all numbers that are counted towards the occurrence-counter. I.e. with input
- 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 like10002000
that should output000
, where most languages would output0
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
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 output88888
([88888]5[88888]66656665666
; length 5, occurs twice), and not666
(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 output111
(333[111]333[111]9[111]
; length 3, occurs thrice), and not333
([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 is33
(1222222[33]4[33]
; length 2, occurs twice) and not222
(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 is8
([8]117741777[8]13[8]2
; length 1, occurs thrice) and not77
(811[77]41[77]781382
/811[77]417[77]81382
; length 2, occurs twice with one invalid) nor1
(8[1][1]774[1]7778[1]382
; length 1, occurs four times with two invalid).
- This applies to all numbers that are counted towards the occurrence-counter. I.e. with input
- 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 like10002000
that should output000
, where most languages would output0
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
code-golf number integer counting subsequence
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
add a comment |Â
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
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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!
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered 35 mins ago
Neil
75.3k744170
75.3k744170
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
edited 3 mins ago
answered 25 mins ago


Mr. Xcoder
30.4k758193
30.4k758193
add a comment |Â
add a comment |Â
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!
add a comment |Â
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!
add a comment |Â
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!
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!
edited 16 mins ago
answered 36 mins ago


TFeld
11.5k2833
11.5k2833
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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