Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,5 +0,0 @@
|
|||
generic
|
||||
type Element_Type is private;
|
||||
type Array_Type is array (Positive range <>) of Element_Type;
|
||||
|
||||
procedure Generic_Shuffle (List : in out Array_Type);
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
with Ada.Numerics.Discrete_Random;
|
||||
|
||||
procedure Generic_Shuffle (List : in out Array_Type) is
|
||||
package Discrete_Random is new Ada.Numerics.Discrete_Random(Result_Subtype => Integer);
|
||||
use Discrete_Random;
|
||||
K : Integer;
|
||||
G : Generator;
|
||||
T : Element_Type;
|
||||
begin
|
||||
Reset (G);
|
||||
for I in reverse List'Range loop
|
||||
K := (Random(G) mod I) + 1;
|
||||
T := List(I);
|
||||
List(I) := List(K);
|
||||
List(K) := T;
|
||||
end loop;
|
||||
end Generic_Shuffle;
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Generic_Shuffle;
|
||||
|
||||
procedure Test_Shuffle is
|
||||
|
||||
type Integer_Array is array (Positive range <>) of Integer;
|
||||
|
||||
Integer_List : Integer_Array
|
||||
:= (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18);
|
||||
procedure Integer_Shuffle is new Generic_Shuffle(Element_Type => Integer,
|
||||
Array_Type => Integer_Array);
|
||||
begin
|
||||
|
||||
for I in Integer_List'Range loop
|
||||
Ada.Text_IO.Put(Integer'Image(Integer_List(I)));
|
||||
end loop;
|
||||
Integer_Shuffle(List => Integer_List);
|
||||
Ada.Text_IO.New_Line;
|
||||
for I in Integer_List'Range loop
|
||||
Ada.Text_IO.Put(Integer'Image(Integer_List(I)));
|
||||
end loop;
|
||||
end Test_Shuffle;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
Dim $a[10]
|
||||
ConsoleWrite('array before permutation:' & @CRLF)
|
||||
For $i = 0 To 9
|
||||
$a[$i] = Random(20,100,1)
|
||||
ConsoleWrite($a[$i] & ' ')
|
||||
Next
|
||||
ConsoleWrite(@CRLF)
|
||||
|
||||
_Permute($a)
|
||||
ConsoleWrite('array after permutation:' & @CRLF)
|
||||
For $i = 0 To UBound($a) -1
|
||||
ConsoleWrite($a[$i] & ' ')
|
||||
Next
|
||||
ConsoleWrite(@CRLF)
|
||||
|
||||
|
||||
Func _Permute(ByRef $array)
|
||||
Local $random, $tmp
|
||||
For $i = UBound($array) -1 To 0 Step -1
|
||||
$random = Random(0,$i,1)
|
||||
$tmp = $array[$random]
|
||||
$array[$random] = $array[$i]
|
||||
$array[$i] = $tmp
|
||||
Next
|
||||
EndFunc
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. knuth-shuffle.
|
||||
|
||||
DATA DIVISION.
|
||||
LOCAL-STORAGE SECTION.
|
||||
01 i PIC 9(8).
|
||||
01 j PIC 9(8).
|
||||
|
||||
01 temp PIC 9(8).
|
||||
|
||||
LINKAGE SECTION.
|
||||
78 Table-Len VALUE 10.
|
||||
01 ttable-area.
|
||||
03 ttable PIC 9(8) OCCURS Table-Len TIMES.
|
||||
|
||||
PROCEDURE DIVISION USING ttable-area.
|
||||
MOVE FUNCTION RANDOM(FUNCTION CURRENT-DATE (11:6)) TO i
|
||||
|
||||
PERFORM VARYING i FROM Table-Len BY -1 UNTIL i = 0
|
||||
COMPUTE j =
|
||||
FUNCTION MOD(FUNCTION RANDOM * 10000, Table-Len) + 1
|
||||
|
||||
MOVE ttable (i) TO temp
|
||||
MOVE ttable (j) TO ttable (i)
|
||||
MOVE temp TO ttable (j)
|
||||
END-PERFORM
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
|
@ -11,7 +11,7 @@ extension randomOp
|
|||
|
||||
for(int i := 0; i < max; i += 1)
|
||||
{
|
||||
var j := randomGenerator.nextInt(i,max);
|
||||
var j := Random.nextInt(i,max);
|
||||
|
||||
self.exchange(i,j)
|
||||
};
|
||||
|
|
@ -20,9 +20,9 @@ extension randomOp
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var a := Array.allocate(MAX).populate::(i => i );
|
||||
|
||||
console.printLine(a.randomize())
|
||||
Console.printLine(a.randomize())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
sequence cards
|
||||
cards = repeat(0,52)
|
||||
integer card,temp
|
||||
|
||||
puts(1,"Before:\n")
|
||||
for i = 1 to 52 do
|
||||
cards[i] = i
|
||||
printf(1,"%d ",cards[i])
|
||||
end for
|
||||
|
||||
for i = 52 to 1 by -1 do
|
||||
card = rand(i)
|
||||
if card != i then
|
||||
temp = cards[card]
|
||||
cards[card] = cards[i]
|
||||
cards[i] = temp
|
||||
end if
|
||||
end for
|
||||
|
||||
puts(1,"\nAfter:\n")
|
||||
for i = 1 to 52 do
|
||||
printf(1,"%d ",cards[i])
|
||||
end for
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
$A = 1, 2, 3, 4, 5
|
||||
Get-Random $A -Count $A.Count
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
function shuffle ($a) {
|
||||
$c = $a.Clone() # make copy to avoid clobbering $a
|
||||
1..($c.Length - 1) | ForEach-Object {
|
||||
$i = Get-Random -Minimum $_ -Maximum $c.Length
|
||||
$c[$_-1],$c[$i] = $c[$i],$c[$_-1]
|
||||
$c[$_-1] # return newly-shuffled value
|
||||
}
|
||||
$c[-1] # last value
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
probe random []
|
||||
probe random [10]
|
||||
probe random [10 20]
|
||||
probe random [10 20 30]
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Knuth shuffle"
|
||||
file: %Knuth_shuffle.r3
|
||||
url: https://rosettacode.org/wiki/Knuth_shuffle
|
||||
]
|
||||
fisher-yates: func [
|
||||
"Fisher-Yates shuffle algorithm - randomly shuffles elements in a block"
|
||||
;Uses the modern variant that works backwards through the array
|
||||
data [series!] "Input block to shuffle"
|
||||
/local i j tmp ;; Local variables: i=current index, j=random index, tmp=swap variable
|
||||
][
|
||||
;; Make a copy of the input block and get its length
|
||||
;; This prevents modification of the original block
|
||||
i: length? data: copy data
|
||||
|
||||
;; Loop from the last element down to the second element
|
||||
;; We stop at 1 because there's no need to swap the first element with itself
|
||||
while [i > 1] [
|
||||
;; Generate random index j from 1 to i (inclusive)
|
||||
j: random i
|
||||
;; Previous version tried to avoid self-swap as an optimization
|
||||
;; but actually it is faster to avoid it!
|
||||
|
||||
;; Three-step swap using path notation for direct block access
|
||||
;; Step 1: Store element at random position j in temporary variable
|
||||
tmp: data/:j
|
||||
|
||||
;; Step 2: Move current element (at position i) to random position j
|
||||
data/:j: data/:i
|
||||
|
||||
;; Step 3: Move stored element to current position i
|
||||
;; Using :tmp to get the value (word evaluation)
|
||||
data/:i: :tmp
|
||||
|
||||
;; Move to previous element (working backwards through the block)
|
||||
i: i - 1
|
||||
]
|
||||
|
||||
;; Return the shuffled block
|
||||
data
|
||||
]
|
||||
|
||||
random/seed 0 ;; to get consistent results
|
||||
|
||||
probe fisher-yates []
|
||||
probe fisher-yates [10]
|
||||
probe fisher-yates [10 20]
|
||||
probe fisher-yates [10 20 30]
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
function shuffle( a )
|
||||
dim i
|
||||
dim r
|
||||
randomize timer
|
||||
for i = lbound( a ) to ubound( a )
|
||||
r = int( rnd * ( ubound( a ) + 1 ) )
|
||||
if r <> i then
|
||||
swap a(i), a(r)
|
||||
end if
|
||||
next
|
||||
shuffle = a
|
||||
end function
|
||||
|
||||
sub swap( byref a, byref b )
|
||||
dim tmp
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp
|
||||
end sub
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
dim a
|
||||
a = array( 1,2,3,4,5,6,7,8,9)
|
||||
wscript.echo "before: ", join( a, ", " )
|
||||
shuffle a
|
||||
wscript.echo "after: ", join( a, ", " )
|
||||
shuffle a
|
||||
wscript.echo "after: ", join( a, ", " )
|
||||
wscript.echo "--"
|
||||
a = array( now(), "cow", 123, true, sin(1), 16.4 )
|
||||
wscript.echo "before: ", join( a, ", " )
|
||||
shuffle a
|
||||
wscript.echo "after: ", join( a, ", " )
|
||||
shuffle a
|
||||
wscript.echo "after: ", join( a, ", " )
|
||||
Loading…
Add table
Add a link
Reference in a new issue