September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,38 @@
|
|||
function encode(string s)
|
||||
string symtab = "abcdefghijklmnopqrstuvwxyz"
|
||||
sequence res = {}
|
||||
for i=1 to length(s) do
|
||||
integer ch = s[i]
|
||||
integer k = find(ch,symtab)
|
||||
res &= k-1
|
||||
for j=k to 2 by -1 do
|
||||
symtab[j] = symtab[j-1]
|
||||
end for
|
||||
symtab[1] = ch
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
function decode(sequence s)
|
||||
string symtab = "abcdefghijklmnopqrstuvwxyz"
|
||||
string res = ""
|
||||
for i=1 to length(s) do
|
||||
integer k = s[i]+1
|
||||
integer ch = symtab[k]
|
||||
res &= ch
|
||||
for j=k to 2 by -1 do
|
||||
symtab[j] = symtab[j-1]
|
||||
end for
|
||||
symtab[1] = ch
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
procedure test(string s)
|
||||
sequence e = encode(s)
|
||||
string d = decode(e)
|
||||
?{s,e,d,{"**ERROR**","ok"}[(s=d)+1]}
|
||||
end procedure
|
||||
test("broood")
|
||||
test("bananaaa")
|
||||
test("hiphophiphop")
|
||||
Loading…
Add table
Add a link
Reference in a new issue