Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,82 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Move_To_Front is
|
||||
|
||||
subtype Lower_Case is Character range 'a' .. 'z';
|
||||
subtype Index is Integer range 0 .. 25;
|
||||
type Table is array (Index) of Lower_Case;
|
||||
Alphabet: constant Table := "abcdefghijklmnopqrstuvwxyz";
|
||||
type Number_String is array(Positive range <>) of Natural;
|
||||
|
||||
function Encode(S: String) return Number_String is
|
||||
Key: Table := Alphabet;
|
||||
|
||||
function Encode(S: String; Tab: in out Table) return Number_String is
|
||||
|
||||
procedure Look_Up(A: in out Table; Ch: Lower_Case; Pos: out Index) is
|
||||
begin
|
||||
for I in A'Range loop
|
||||
if A(I) = Ch then
|
||||
Pos := I;
|
||||
A := A(Pos) & A(A'First .. Pos-1) & A(Pos+1 .. A'Last);
|
||||
return;
|
||||
end if;
|
||||
end loop;
|
||||
raise Program_Error with "unknown character";
|
||||
end Look_Up;
|
||||
|
||||
Empty: Number_String(1 .. 0);
|
||||
Result: Natural;
|
||||
begin
|
||||
if S'Length = 0 then
|
||||
return Empty;
|
||||
else
|
||||
Look_Up(Tab, S(S'First), Result);
|
||||
return Result & Encode(S(S'First+1 .. S'Last), Tab);
|
||||
end if;
|
||||
end Encode;
|
||||
|
||||
begin
|
||||
return Encode(S, Key);
|
||||
end Encode;
|
||||
|
||||
function Decode(N: Number_String) return String is
|
||||
Key: Table := Alphabet;
|
||||
|
||||
function Decode(N: Number_String; Tab: in out Table) return String is
|
||||
|
||||
procedure Look_Up(A: in out Table; Pos: Index; Ch: out Lower_Case) is
|
||||
begin
|
||||
Ch := A(Pos);
|
||||
A := A(Pos) & A(A'First .. Pos-1) & A(Pos+1 .. A'Last);
|
||||
end Look_Up;
|
||||
|
||||
Result: String(N'Range);
|
||||
begin
|
||||
for I in N'Range loop
|
||||
Look_Up(Tab, N(I), Result(I));
|
||||
end loop;
|
||||
return Result;
|
||||
end Decode;
|
||||
|
||||
begin
|
||||
return Decode(N, Key);
|
||||
end Decode;
|
||||
|
||||
procedure Encode_Write_Check(S: String) is
|
||||
N: Number_String := Encode(S);
|
||||
T: String := Decode(N);
|
||||
Check: String := (if S=T then "Correct!" else "*WRONG*!");
|
||||
begin
|
||||
Ada.Text_IO.Put("'" & S & "' encodes to");
|
||||
for Num of N loop
|
||||
Ada.Text_IO.Put(Integer'Image(Num));
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line(". This decodes to '" & T & "'. " & Check);
|
||||
end Encode_Write_Check;
|
||||
|
||||
begin
|
||||
Encode_Write_Check("broood");
|
||||
Encode_Write_Check("bananaaa");
|
||||
Encode_Write_Check("hiphophiphop");
|
||||
end Move_To_Front;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
symbolTable: @`a`..`z`
|
||||
symbolTable: @'a'..'z'
|
||||
|
||||
encodeWord: function [s][
|
||||
symt: new symbolTable
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
Function Test-MTF
|
||||
{
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,Position=0)]
|
||||
[string]$word,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$SymbolTable = 'abcdefghijklmnopqrstuvwxyz'
|
||||
)
|
||||
Begin
|
||||
{
|
||||
Function Encode
|
||||
{
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,Position=0)]
|
||||
[string]$word,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$SymbolTable = 'abcdefghijklmnopqrstuvwxyz'
|
||||
)
|
||||
foreach ($letter in $word.ToCharArray())
|
||||
{
|
||||
$index = $SymbolTable.IndexOf($letter)
|
||||
|
||||
$prop = [ordered]@{
|
||||
Input = $letter
|
||||
Output = [int]$index
|
||||
SymbolTable = $SymbolTable
|
||||
}
|
||||
New-Object PSobject -Property $prop
|
||||
$SymbolTable = $SymbolTable.Remove($index,1).Insert(0,$letter)
|
||||
}
|
||||
}
|
||||
Function Decode
|
||||
{
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,Position=0)]
|
||||
[int[]]$index,
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$SymbolTable = 'abcdefghijklmnopqrstuvwxyz'
|
||||
)
|
||||
foreach ($i in $index)
|
||||
{
|
||||
#Write-host $i -ForegroundColor Red
|
||||
$letter = $SymbolTable.Chars($i)
|
||||
|
||||
$prop = [ordered]@{
|
||||
Input = $i
|
||||
Output = $letter
|
||||
SymbolTable = $SymbolTable
|
||||
}
|
||||
New-Object PSObject -Property $prop
|
||||
$SymbolTable = $SymbolTable.Remove($i,1).Insert(0,$letter)
|
||||
}
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
#Encoding
|
||||
Write-Host "Encoding $word" -NoNewline
|
||||
$Encoded = (Encode -word $word).output
|
||||
Write-Host -NoNewline ": $($Encoded -join ',')"
|
||||
|
||||
#Decoding
|
||||
Write-Host "`nDecoding $($Encoded -join ',')" -NoNewline
|
||||
$Decoded = (Decode -index $Encoded).output -join ''
|
||||
Write-Host -NoNewline ": $Decoded`n"
|
||||
}
|
||||
End{}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
Function mtf_encode(s)
|
||||
'create the array list and populate it with the initial symbol position
|
||||
Set symbol_table = CreateObject("System.Collections.ArrayList")
|
||||
For j = 97 To 122 'a to z in decimal.
|
||||
symbol_table.Add Chr(j)
|
||||
Next
|
||||
output = ""
|
||||
For i = 1 To Len(s)
|
||||
char = Mid(s,i,1)
|
||||
If i = Len(s) Then
|
||||
output = output & symbol_table.IndexOf(char,0)
|
||||
symbol_table.RemoveAt(symbol_table.LastIndexOf(char))
|
||||
symbol_table.Insert 0,char
|
||||
Else
|
||||
output = output & symbol_table.IndexOf(char,0) & " "
|
||||
symbol_table.RemoveAt(symbol_table.LastIndexOf(char))
|
||||
symbol_table.Insert 0,char
|
||||
End If
|
||||
Next
|
||||
mtf_encode = output
|
||||
End Function
|
||||
|
||||
Function mtf_decode(s)
|
||||
'break the function argument into an array
|
||||
code = Split(s," ")
|
||||
'create the array list and populate it with the initial symbol position
|
||||
Set symbol_table = CreateObject("System.Collections.ArrayList")
|
||||
For j = 97 To 122 'a to z in decimal.
|
||||
symbol_table.Add Chr(j)
|
||||
Next
|
||||
output = ""
|
||||
For i = 0 To UBound(code)
|
||||
char = symbol_table(code(i))
|
||||
output = output & char
|
||||
If code(i) <> 0 Then
|
||||
symbol_table.RemoveAt(symbol_table.LastIndexOf(char))
|
||||
symbol_table.Insert 0,char
|
||||
End If
|
||||
Next
|
||||
mtf_decode = output
|
||||
End Function
|
||||
|
||||
'Testing the functions
|
||||
wordlist = Array("broood","bananaaa","hiphophiphop")
|
||||
For Each word In wordlist
|
||||
WScript.StdOut.Write word & " encodes as " & mtf_encode(word) & " and decodes as " &_
|
||||
mtf_decode(mtf_encode(word)) & "."
|
||||
WScript.StdOut.WriteBlankLines(1)
|
||||
Next
|
||||
Loading…
Add table
Add a link
Reference in a new issue