Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
|
|
@ -0,0 +1,30 @@
|
|||
main :: [sys_message]
|
||||
main = [Stdout (lay (map test ["broood", "bananaaa", "hiphophiphop"]))]
|
||||
|
||||
test :: [char]->[char]
|
||||
test str = str ++ " -> " ++ show encoded ++ " -> " ++ decoded ++ result
|
||||
where alph = "abcdefghijklmnopqrstuvwxyz"
|
||||
encoded = enc alph str
|
||||
decoded = dec alph encoded
|
||||
result = " (ok)", if str == decoded
|
||||
result = " (fail)", otherwise
|
||||
|
||||
enc :: [*]->[*]->[num]
|
||||
enc symtab [] = []
|
||||
enc symtab (x:xs) = find x symtab : enc (movetofront x symtab) xs
|
||||
|
||||
dec :: [*]->[num]->[*]
|
||||
dec symtab [] = []
|
||||
dec symtab (x:xs) = c : dec (movetofront c symtab) xs where c = symtab ! x
|
||||
|
||||
movetofront :: *->[*]->[*]
|
||||
movetofront x xs = x:remove x xs
|
||||
|
||||
remove :: *->[*]->[*]
|
||||
remove x [] = []
|
||||
remove x (x:xs) = remove x xs
|
||||
remove x (y:xs) = y:remove x xs
|
||||
|
||||
find :: *->[*]->num
|
||||
find x (x:xs) = 0
|
||||
find x (y:xs) = 1 + find x xs
|
||||
Loading…
Add table
Add a link
Reference in a new issue