Skip to content

Instantly share code, notes, and snippets.

@lashtear
Created April 25, 2023 00:54
Show Gist options
  • Save lashtear/289d9960dda6633664d72efa46cd57e2 to your computer and use it in GitHub Desktop.
Save lashtear/289d9960dda6633664d72efa46cd57e2 to your computer and use it in GitHub Desktop.
a tiny (and slow) Burrows-Wheeler Transform in Haskell
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