Created
August 9, 2014 10:09
-
-
Save tomstuart/9f5de3cd41cd9897c4d4 to your computer and use it in GitHub Desktop.
Revisions
-
tomstuart created this gist
Aug 9, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ class BWT def encode(string) chars = string.chars + ['$'] chars.each_index.map(&chars.method(:rotate)).sort.map(&:last).join end def decode(string) chars = string.chars chars.inject([]) { |table| chars.zip(table).sort }. map(&:join).detect { |s| s.end_with?('$') }.chop end end