Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,54 @@
movetofront = proc (s: string, c: char) returns (string) signals (not_found)
if string$indexc(c, s) = 0 then signal not_found end
next: array[char] := array[char]$[c]
for sc: char in string$chars(s) do
if sc = c then continue end
array[char]$addh(next, sc)
end
return(string$ac2s(next))
end movetofront
encode = proc (s, alph: string) returns (sequence[int]) signals (not_found)
encoded: array[int] := array[int]$[]
for c: char in string$chars(s) do
array[int]$addh(encoded, string$indexc(c, alph) - 1)
alph := movetofront(alph, c) resignal not_found
end
return(sequence[int]$a2s(encoded))
end encode
decode = proc (data: sequence[int], alph: string) returns (string) signals (not_found)
decoded: array[char] := array[char]$[]
for n: int in sequence[int]$elements(data) do
c: char := alph[n + 1]
array[char]$addh(decoded, c)
alph := movetofront(alph, c) resignal not_found
end
return(string$ac2s(decoded))
end decode
print_seq = proc (seq: sequence[int], s: stream)
for n: int in sequence[int]$elements(seq) do
stream$puts(s, int$unparse(n) || " ")
end
end print_seq
start_up = proc ()
po: stream := stream$primary_output()
words: sequence[string] := sequence[string]$["broood", "bananaaa", "hiphophiphop"]
alph: string := "abcdefghijklmnopqrstuvwxyz"
for word: string in sequence[string]$elements(words) do
stream$puts(po, word || " -> ")
encoded: sequence[int] := encode(word, alph)
print_seq(encoded, po)
stream$puts(po, "-> ")
decoded: string := decode(encoded, alph)
stream$puts(po, decoded)
if word = decoded
then stream$putl(po, " ok")
else stream$putl(po, " fail")
end
end
end start_up