Author: | rks |
---|---|
Mode: | factor |
Date: | Sun, 12 Jun 2011 13:50:41 |
USING: arrays combinators kernel sequences string ; IN: mtf : mtf ( seq i -- seq ) cut [ rest ] [ first ] bi [ append ] dip prefix ; : encode ( alphabet str -- seq ) >array [ over index [ mtf ] keep ] map nip ; : decode ( alphabet seq -- str ) [ over dupd nth [ mtf ] dip ] map >string nip ;