Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
26
Task/Move-to-front-algorithm/11l/move-to-front-algorithm.11l
Normal file
26
Task/Move-to-front-algorithm/11l/move-to-front-algorithm.11l
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
V symboltable = Array(‘a’..‘z’)
|
||||
|
||||
F move2front_encode(strng)
|
||||
[Int] sequence
|
||||
V pad = copy(:symboltable)
|
||||
L(char) strng
|
||||
V indx = pad.index(char)
|
||||
sequence.append(indx)
|
||||
pad = [pad.pop(indx)] [+] pad
|
||||
R sequence
|
||||
|
||||
F move2front_decode(sequence)
|
||||
[Char] chars
|
||||
V pad = copy(:symboltable)
|
||||
L(indx) sequence
|
||||
V char = pad[indx]
|
||||
chars.append(char)
|
||||
pad = [pad.pop(indx)] [+] pad
|
||||
R chars.join(‘’)
|
||||
|
||||
L(s) [‘broood’, ‘bananaaa’, ‘hiphophiphop’]
|
||||
V encode = move2front_encode(s)
|
||||
print(‘#14 encodes to #.’.format(s, encode), end' ‘, ’)
|
||||
V decode = move2front_decode(encode)
|
||||
print(‘which decodes back to #.’.format(decode))
|
||||
assert(s == decode, ‘Whoops!’)
|
||||
Loading…
Add table
Add a link
Reference in a new issue