14 lines
414 B
Text
14 lines
414 B
Text
(defvarl eof "\xDC00")
|
|
|
|
(defun bwt (str)
|
|
(if (contains eof str)
|
|
(error "~s: input may not contain ~a" %fun% eof))
|
|
(let ((seof `@str@eof`))
|
|
(flow 0..(len seof) (mapcar (op rot seof)) sort (mappend last))))
|
|
|
|
(defun ibwt (str)
|
|
(let* ((ch (tuples 1 str))
|
|
(row (sort ch)))
|
|
(dotimes (i (pred (len str)))
|
|
(upd row (mapcar append ch) nsort))
|
|
[(find-if (op ends-with eof) row) 0..-1]))
|