Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,50 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Ada.Strings.Unbounded;
|
||||
|
||||
procedure Best_Shuffle is
|
||||
|
||||
function Best_Shuffle (S : String) return String;
|
||||
|
||||
function Best_Shuffle (S : String) return String is
|
||||
T : String (S'Range) := S;
|
||||
Tmp : Character;
|
||||
begin
|
||||
for I in S'Range loop
|
||||
for J in S'Range loop
|
||||
if I /= J and S (I) /= T (J) and S (J) /= T (I) then
|
||||
Tmp := T (I);
|
||||
T (I) := T (J);
|
||||
T (J) := Tmp;
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
return T;
|
||||
end Best_Shuffle;
|
||||
|
||||
Test_Cases : constant array (1 .. 6)
|
||||
of Ada.Strings.Unbounded.Unbounded_String :=
|
||||
(Ada.Strings.Unbounded.To_Unbounded_String ("abracadabra"),
|
||||
Ada.Strings.Unbounded.To_Unbounded_String ("seesaw"),
|
||||
Ada.Strings.Unbounded.To_Unbounded_String ("elk"),
|
||||
Ada.Strings.Unbounded.To_Unbounded_String ("grrrrrr"),
|
||||
Ada.Strings.Unbounded.To_Unbounded_String ("up"),
|
||||
Ada.Strings.Unbounded.To_Unbounded_String ("a"));
|
||||
|
||||
begin -- main procedure
|
||||
for Test_Case in Test_Cases'Range loop
|
||||
declare
|
||||
Original : constant String := Ada.Strings.Unbounded.To_String
|
||||
(Test_Cases (Test_Case));
|
||||
Shuffle : constant String := Best_Shuffle (Original);
|
||||
Score : Natural := 0;
|
||||
begin
|
||||
for I in Original'Range loop
|
||||
if Original (I) = Shuffle (I) then
|
||||
Score := Score + 1;
|
||||
end if;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line (Original & ", " & Shuffle & ", (" &
|
||||
Natural'Image (Score) & " )");
|
||||
end;
|
||||
end loop;
|
||||
end Best_Shuffle;
|
||||
|
|
@ -35,7 +35,7 @@ extension op
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
new string[]{"abracadabra", "seesaw", "grrrrrr", "pop", "up", "a"}.forEach::(s)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
# Calculate best possible shuffle score for a given string
|
||||
# (Split out into separate function so we can use it separately in our output)
|
||||
function Get-BestScore ( [string]$String )
|
||||
{
|
||||
# Convert to array of characters, group identical characters,
|
||||
# sort by frequecy, get size of first group
|
||||
$MostRepeats = $String.ToCharArray() |
|
||||
Group |
|
||||
Sort Count -Descending |
|
||||
Select -First 1 -ExpandProperty Count
|
||||
|
||||
# Return count of most repeated character minus all other characters (math simplified)
|
||||
return [math]::Max( 0, 2 * $MostRepeats - $String.Length )
|
||||
}
|
||||
|
||||
function Get-BestShuffle ( [string]$String )
|
||||
{
|
||||
# Convert to arrays of characters, one for comparison, one for manipulation
|
||||
$S1 = $String.ToCharArray()
|
||||
$S2 = $String.ToCharArray()
|
||||
|
||||
# Calculate best possible score as our goal
|
||||
$BestScore = Get-BestScore $String
|
||||
|
||||
# Unshuffled string has score equal to number of characters
|
||||
$Length = $String.Length
|
||||
$Score = $Length
|
||||
|
||||
# While still striving for perfection...
|
||||
While ( $Score -gt $BestScore )
|
||||
{
|
||||
# For each character
|
||||
ForEach ( $i in 0..($Length-1) )
|
||||
{
|
||||
# If the shuffled character still matches the original character...
|
||||
If ( $S1[$i] -eq $S2[$i] )
|
||||
{
|
||||
# Swap it with a random character
|
||||
# (Random character $j may be the same as or may even be
|
||||
# character $i. The minor impact on speed was traded for
|
||||
# a simple solution to guarantee randomness.)
|
||||
$j = Get-Random -Maximum $Length
|
||||
$S2[$i], $S2[$j] = $S2[$j], $S2[$i]
|
||||
}
|
||||
}
|
||||
# Count the number of indexes where the two arrays match
|
||||
$Score = ( 0..($Length-1) ).Where({ $S1[$_] -eq $S2[$_] }).Count
|
||||
}
|
||||
# Put it back into a string
|
||||
$Shuffle = ( [string[]]$S2 -join '' )
|
||||
return $Shuffle
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
ForEach ( $String in ( 'abracadabra', 'seesaw', 'elk', 'grrrrrr', 'up', 'a' ) )
|
||||
{
|
||||
$Shuffle = Get-BestShuffle $String
|
||||
$Score = Get-BestScore $String
|
||||
"$String, $Shuffle, ($Score)"
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
'Best Shuffle Task
|
||||
'VBScript Implementation
|
||||
|
||||
Function bestshuffle(s)
|
||||
Dim arr:Redim arr(Len(s)-1)
|
||||
|
||||
'The Following Does the toCharArray() Functionality
|
||||
For i = 0 To Len(s)-1
|
||||
arr(i) = Mid(s, i + 1, 1)
|
||||
Next
|
||||
|
||||
arr = shuffler(arr) 'Make this line a comment for deterministic solution
|
||||
For i = 0 To UBound(arr):Do
|
||||
If arr(i) <> Mid(s, i + 1, 1) Then Exit Do
|
||||
For j = 0 To UBound(arr)
|
||||
If arr(i) <> arr(j) And arr(i) <> Mid(s, j + 1, 1) And arr(j) <> Mid(s, i + 1, 1) Then
|
||||
tmp = arr(i)
|
||||
arr(i) = arr(j)
|
||||
arr(j) = tmp
|
||||
End If
|
||||
Next
|
||||
Loop While False:Next
|
||||
|
||||
shuffled_word = Join(arr,"")
|
||||
|
||||
'This section is the scorer
|
||||
score = 0
|
||||
For k = 1 To Len(s)
|
||||
If Mid(s,k,1) = Mid(shuffled_word,k,1) Then
|
||||
score = score + 1
|
||||
End If
|
||||
Next
|
||||
|
||||
bestshuffle = shuffled_word & ",(" & score & ")"
|
||||
End Function
|
||||
|
||||
Function shuffler(array)
|
||||
Set rand = CreateObject("System.Random")
|
||||
For i = UBound(array) to 0 Step -1
|
||||
r = rand.next_2(0, i + 1)
|
||||
tmp = array(i)
|
||||
array(i) = array(r)
|
||||
array(r) = tmp
|
||||
Next
|
||||
shuffler = array
|
||||
End Function
|
||||
|
||||
'Testing the function
|
||||
word_list = Array("abracadabra","seesaw","elk","grrrrrr","up","a")
|
||||
For Each word In word_list
|
||||
WScript.StdOut.WriteLine word & "," & bestshuffle(word)
|
||||
Next
|
||||
Loading…
Add table
Add a link
Reference in a new issue