Move-to-front algorithm: Difference between revisions

Content added Content deleted
No edit summary
(Added Bracmat example)
Line 417: Line 417:
bananaaa 1,1,13,1,1,1,0,0 bananaaa
bananaaa 1,1,13,1,1,1,0,0 bananaaa
hiphophiphop 7,8,15,2,15,2,2,3,2,2,3,2 hiphophiphop</pre>
hiphophiphop 7,8,15,2,15,2,2,3,2,2,3,2 hiphophiphop</pre>

=={{header|Bracmat}}==
<lang bracmat> ( encode
= string symboltable
. !arg:(?string.?symboltable)
& vap
$ ( (
= A Z i
. !symboltable:?A [?i !arg ?Z
& !arg !A !Z:?symboltable
& !i
)
. !string
)
)
& ( decode
= indices symboltable
. !arg:(?indices.?symboltable)
& str
$ ( map
$ ( (
= A Z symbol
. !symboltable:?A [!arg %?symbol ?Z
& !symbol !A !Z:?symboltable
& !symbol
)
. !indices
)
)
)
& ( test
= string symboltable encoded decoded
. !arg:(?string.?symboltable)
& put$str$("input:" !string ", ")
& encode$(!string.!symboltable):?encoded
& put$("encoded:" !encoded ", ")
& decode$(!encoded.!symboltable):?decoded
& put$str$("decoded:" !decoded ", ")
& ( !string:!decoded
& out$OK
| out$WRONG
)
)
& a b c d e f g h i j k l m n o p q r s t y v w x y z
: ?symboltable
& test$(broood.!symboltable)
& test$(bananaaa.!symboltable)
& test$(hiphophiphop.!symboltable)</lang>


=={{header|C}}==
=={{header|C}}==