All the k-mers/n-grams Intro
We have had histograms and counting, but not listing all of them.
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. This is a language agnostic code-golf edition of this year's sixth problem.
I have explicit permission to post this challenge here from the original author of the competition. Feel free to verify by following the provided link and contacting the author.
Problem
The term k-mer typically refers to all the possible substrings of length k that are contained in a string. In computational genomics, k-mers refer to all the possible subsequences (of length k) from a read obtained through DNA Sequencing. Write a function/program that takes a string and k (the substring
length) and returns/outputs a vector of the k-mers of the original string.
Examples
[4,&quot;ATCGAAGGTCGT&quot;] → [&quot;ATCG&quot;,&quot;TCGA&quot;,&quot;CGAA&quot;,&quot;GAAG&quot;,&quot;AAGG&quot;,&quot;AGGT&quot;,&quot;GGTC&quot;,&quot;GTCG&quot;,&quot;TCGT&quot;]
k &gt; string length? Return nothing/any empty result:
[4,&quot;AC&quot;] → [] or &quot;&quot; or [&quot;&quot;]
Jelly, 1 byte

ṡ


Jelly has a single byte dyadic atom for this very operation

Try it online! (the footer splits the resulting list with newlines, to avoid a mushed representation being printed.)