Anonymous user
Move-to-front algorithm: Difference between revisions
m
→version 2: used a more idiomatic version to append an arithmetic difference (appended to a string).
m (→version 2: used a more idiomatic version to append an arithmetic difference (appended to a string).) |
|||
Line 1,825:
parse arg xxx; if xxx='' then xxx= 'broood bananaaa hiphophiphop' /*use the default?*/
one=1 /*(offset) for this task's requirement.*/
do j=1 for words(xxx);
@= 'abcdefghijklmnopqrstuvwxyz'; @@=@ /*symbol table: the lowercase alphabet */
$= /*set the decode string to a null. */
do k=1 for length(x);
_=pos(z, @); if _==0 then iterate /*the symbol position in symbol table. */
$=$ (_ - one);
end /*k*/ /* [↑] the move─to─front encoding. */
!= /*set the encode string to a null. */
do m=1 for words($);
y=substr(@@, n, 1);
@@=y || delstr(@@, n, 1) /*rebuild the symbol table string. */
end /*m*/ /* [↑] the move─to─front decoding. */
say ' word: ' left(x, 20)
end /*j*/ /*stick a fork in it, we're all done. */</lang>
{{out|output|text= when using the default input:}}
|