forked from liuxinyu95/AlgoXY
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BWT: Added a better inverse BWT algorithm in Python, Haskell naive ve…
…rsion is finished.
- Loading branch information
1 parent
91b974b
commit fa8c0f6
Showing
4 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module BWT where | ||
|
||
import Data.List | ||
|
||
-- Algorithm 1, Naive version | ||
|
||
bwt :: (Ord a)=>[a]->([a], Int) | ||
bwt s = (map last m, i) where | ||
m = sort [ drop i s ++ take i s | i<-[1..length s]] | ||
(Just i) = elemIndex s m | ||
|
||
ibwt :: (Ord a)=> ([a], Int) -> [a] | ||
ibwt (r, i) = m !! i where | ||
m = iterate f (replicate n []) !! n | ||
f = sort . zipWith (:) r | ||
n = length r | ||
|
||
-- Algorithm 2, |
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