Skip to content

Instantly share code, notes, and snippets.

@andreypopp
Created June 5, 2011 12:32
Show Gist options
  • Save andreypopp/1008921 to your computer and use it in GitHub Desktop.
Save andreypopp/1008921 to your computer and use it in GitHub Desktop.
Prelude> let ngrams n seq@(_:tail) | length seq >= n = (take n seq):(ngrams n tail); ngrams _ _ = []
Prelude> ngrams 1 [1,2,3]
[[1],[2],[3]]
Prelude> ngrams 2 [1,2,3]
[[1,2],[2,3]]
Prelude> ngrams 3 [1,2,3]
[[1,2,3]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment