Created
April 25, 2023 00:54
-
-
Save lashtear/289d9960dda6633664d72efa46cd57e2 to your computer and use it in GitHub Desktop.
a tiny (and slow) Burrows-Wheeler Transform in Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BWT where | |
import Data.List (sort) | |
ibwt :: String -> String | |
ibwt s = | |
let len = length s | |
cs = cycle s in | |
head $ | |
head $ | |
take 1 $ | |
drop (len-1) $ | |
iterate (sort . (zipWith (:) s)) $ | |
sort $ | |
map (:[]) s | |
bwt :: String -> String | |
bwt s = | |
let len = length s | |
cs = cycle s in | |
map last $ | |
sort $ | |
take len $ | |
map (take len) $ | |
iterate (drop 1) cs | |
-- *BWT> bwt "\STXHello world" | |
-- "do\STXlHrellwo " | |
-- *BWT> ibwt "do\STXlHrellwo " | |
-- "\STXHello world" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment