Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Question

Commonmark migration
Source Link

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

Inputs

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

Output

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

Win Criteria

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Examples

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

(note the trailing newline)

1 > \r\n(appears 12 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times). : also appears 12 times
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

(note the trailing newline)

1 > \r\n(appears 12 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times). : also appears 12 times
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

Inputs

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

Output

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

Win Criteria

This is , so lowest bytes wins; usual exceptions etc. apply.

Examples

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

(note the trailing newline)

1 > \r\n(appears 12 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times). : also appears 12 times
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

Became Hot Network Question
Tweeted twitter.com/StackCodeGolf/status/1229782814717026307
added 64 characters in body
Source Link

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

(note the trailing newline)

1 > \r\n(appears 1112 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times). : also appears 12 times
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

1 > \r\n(appears 11 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times)
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

(note the trailing newline)

1 > \r\n(appears 12 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times). : also appears 12 times
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

added 11 characters in body
Source Link

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

1 > \r\n(appears 11 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times)
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

1 > \r\n(appears 11 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times)
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

The purpose of this task is to write a program or function to find the most common substring within a given string, of the specified length.

##Inputs##

  1. A string, s, of any length and characters that are valid as inputs for your language.
  2. A number, n, indicating the length of substring to find. Guaranteed to be equal to or less than the length of the string.

##Output##

The most common (case-sensitive) substring of s of length n. In the case of a tie, any of the options may be output.

##Win Criteria##

This is , so lowest bytes wins; usual exceptions etc. apply.

##Examples##

Hello, World!, 1 > l (appears 3 times)
Hello! Cheerio!, 2 > o! (appears twice)
The Cat sat on the mat, 2 > at (appears three times)
The Cat sat on the mat, 3 > at or he (both with trailing spaces. Both appear twice - note case-sensitivity so The and the are different substrings)
Mississippi, 4 > issi (appears twice, note that the two occurrences overlap each other)

Some more examples, all using the same input string*##

Bb:maj/2
F:maj/5
Bb:maj/2
G:9/3
Bb:maj7
F:maj/3
G:min7
C:sus4(b7,9)
C:sus4(b7,9)
C:sus4(b7,9)
F:maj
F:maj

1 > \r\n(appears 11 times, counting \r\n as a single character - my choice, your code may differ on this - otherwise either \r or \n appear the same number of times)
2 > :m (appears 8 times)
3 > :ma or maj (appears 7 times)
4 > :maj (appears 7 times)
5 > F:maj or \r\nF:ma or :maj/ (appears 4 times)
14 > \r\nC:sus4(b7,9)\r\n (appears 3 times)

(* input is taken from How predictable is popular music?. The result of this task might be used, for example, to find the most efficient way to apply a substitution in order to compress the string)

Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /