Skip to content

Instantly share code, notes, and snippets.

@naoto-ogawa
Created August 4, 2019 08:20
Show Gist options
  • Save naoto-ogawa/9b95a38c1cf2f1e7c1173346c7f43d35 to your computer and use it in GitHub Desktop.
Save naoto-ogawa/9b95a38c1cf2f1e7c1173346c7f43d35 to your computer and use it in GitHub Desktop.
Suffix Arary (inefficient)
import Data.List
suffixArray :: [Char] -> [Int]
suffixArray xs = sortBy (\x y -> compare (drop x xs) (drop y xs) ) [0..(length xs - 1)]
{-
> suffixArray "abracadabra"
[10,7,0,3,5,8,1,4,6,9,2]
> suffixArray "banana"
[5,3,1,0,4,2]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment