Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,43 @@
|
|||
import util.
|
||||
|
||||
go =>
|
||||
Strings = ["broood", "bananaaa", "hiphophiphop"],
|
||||
foreach(String in Strings)
|
||||
check(String)
|
||||
end,
|
||||
nl.
|
||||
|
||||
% adjustments to 1-based index
|
||||
encode(String) = [Pos,Table] =>
|
||||
Table = "abcdefghijklmnopqrstuvwxyz",
|
||||
Pos = [],
|
||||
Len = String.length,
|
||||
foreach({C,I} in zip(String,1..Len))
|
||||
Pos := Pos ++ [find_first_of(Table,C)-1],
|
||||
if Len > I then
|
||||
Table := [C] ++ delete(Table,C)
|
||||
end
|
||||
end.
|
||||
|
||||
decode(Pos) = String =>
|
||||
Table = "abcdefghijklmnopqrstuvwxyz",
|
||||
String = [],
|
||||
foreach(P in Pos)
|
||||
C = Table[P+1],
|
||||
Table := [C] ++ delete(Table,C),
|
||||
String := String ++ [C]
|
||||
end.
|
||||
|
||||
% Check the result
|
||||
check(String) =>
|
||||
[Pos,Table] = encode(String),
|
||||
String2 = decode(Pos),
|
||||
if length(String) < 100 then
|
||||
println(pos=Pos),
|
||||
println(table=Table),
|
||||
println(string2=String2)
|
||||
else
|
||||
printf("String is too long to print (%d chars)\n", length(String))
|
||||
end,
|
||||
println(cond(String != String2, "not ", "") ++ "same"),
|
||||
nl.
|
||||
Loading…
Add table
Add a link
Reference in a new issue