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; use Ada.Text_IO;
|
||||
with Ada.Numerics.Discrete_Random;
|
||||
|
||||
procedure Test_Bogosort is
|
||||
generic
|
||||
type Ordered is private;
|
||||
type List is array (Positive range <>) of Ordered;
|
||||
with function "<" (L, R : Ordered) return Boolean is <>;
|
||||
procedure Bogosort (Data : in out List);
|
||||
|
||||
procedure Bogosort (Data : in out List) is
|
||||
function Sorted return Boolean is
|
||||
begin
|
||||
for I in Data'First..Data'Last - 1 loop
|
||||
if not (Data (I) < Data (I + 1)) then
|
||||
return False;
|
||||
end if;
|
||||
end loop;
|
||||
return True;
|
||||
end Sorted;
|
||||
subtype Index is Integer range Data'Range;
|
||||
package Dices is new Ada.Numerics.Discrete_Random (Index);
|
||||
use Dices;
|
||||
Dice : Generator;
|
||||
procedure Shuffle is
|
||||
J : Index;
|
||||
Temp : Ordered;
|
||||
begin
|
||||
for I in Data'Range loop
|
||||
J := Random (Dice);
|
||||
Temp := Data (I);
|
||||
Data (I) := Data (J);
|
||||
Data (J) := Temp;
|
||||
end loop;
|
||||
end Shuffle;
|
||||
begin
|
||||
while not Sorted loop
|
||||
Shuffle;
|
||||
end loop;
|
||||
end Bogosort;
|
||||
|
||||
type List is array (Positive range <>) of Integer;
|
||||
procedure Integer_Bogosort is new Bogosort (Integer, List);
|
||||
Sequence : List := (7,6,3,9);
|
||||
begin
|
||||
Integer_Bogosort (Sequence);
|
||||
for I in Sequence'Range loop
|
||||
Put (Integer'Image (Sequence (I)));
|
||||
end loop;
|
||||
end Test_Bogosort;
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
identification division.
|
||||
program-id. bogo-sort-program.
|
||||
data division.
|
||||
working-storage section.
|
||||
01 array-to-sort.
|
||||
05 item-table.
|
||||
10 item pic 999
|
||||
occurs 10 times.
|
||||
01 randomization.
|
||||
05 random-seed pic 9(8).
|
||||
05 random-index pic 9.
|
||||
01 flags-counters-etc.
|
||||
05 array-index pic 99.
|
||||
05 adjusted-index pic 99.
|
||||
05 temporary-storage pic 999.
|
||||
05 shuffles pic 9(8)
|
||||
value zero.
|
||||
05 sorted pic 9.
|
||||
01 numbers-without-leading-zeros.
|
||||
05 item-no-zeros pic z(4).
|
||||
05 shuffles-no-zeros pic z(8).
|
||||
procedure division.
|
||||
control-paragraph.
|
||||
accept random-seed from time.
|
||||
move function random(random-seed) to item(1).
|
||||
perform random-item-paragraph varying array-index from 2 by 1
|
||||
until array-index is greater than 10.
|
||||
display 'BEFORE SORT:' with no advancing.
|
||||
perform show-array-paragraph varying array-index from 1 by 1
|
||||
until array-index is greater than 10.
|
||||
display ''.
|
||||
perform shuffle-paragraph through is-it-sorted-paragraph
|
||||
until sorted is equal to 1.
|
||||
display 'AFTER SORT: ' with no advancing.
|
||||
perform show-array-paragraph varying array-index from 1 by 1
|
||||
until array-index is greater than 10.
|
||||
display ''.
|
||||
move shuffles to shuffles-no-zeros.
|
||||
display shuffles-no-zeros ' SHUFFLES PERFORMED.'
|
||||
stop run.
|
||||
random-item-paragraph.
|
||||
move function random to item(array-index).
|
||||
show-array-paragraph.
|
||||
move item(array-index) to item-no-zeros.
|
||||
display item-no-zeros with no advancing.
|
||||
shuffle-paragraph.
|
||||
perform shuffle-items-paragraph,
|
||||
varying array-index from 1 by 1
|
||||
until array-index is greater than 10.
|
||||
add 1 to shuffles.
|
||||
is-it-sorted-paragraph.
|
||||
move 1 to sorted.
|
||||
perform item-in-order-paragraph varying array-index from 1 by 1,
|
||||
until sorted is equal to zero
|
||||
or array-index is equal to 10.
|
||||
shuffle-items-paragraph.
|
||||
move function random to random-index.
|
||||
add 1 to random-index giving adjusted-index.
|
||||
move item(array-index) to temporary-storage.
|
||||
move item(adjusted-index) to item(array-index).
|
||||
move temporary-storage to item(adjusted-index).
|
||||
item-in-order-paragraph.
|
||||
add 1 to array-index giving adjusted-index.
|
||||
if item(array-index) is greater than item(adjusted-index)
|
||||
then move zero to sorted.
|
||||
|
|
@ -16,10 +16,10 @@ extension op
|
|||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
public Program()
|
||||
{
|
||||
var list := new int[]{3, 4, 1, 8, 7, -2, 0};
|
||||
auto list := new int[]{3, 4, 1, 8, 7, -2, 0};
|
||||
|
||||
console.printLine("before:", list.asEnumerable());
|
||||
console.printLine("after :", list.bogoSorter().asEnumerable())
|
||||
Console.printLine("before:", list.asEnumerable());
|
||||
Console.printLine("after :", list.bogoSorter().asEnumerable())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
function shuffle(sequence s)
|
||||
object temp
|
||||
integer j
|
||||
for i = length(s) to 1 by -1 do
|
||||
j = rand(i)
|
||||
if i != j then
|
||||
temp = s[i]
|
||||
s[i] = s[j]
|
||||
s[j] = temp
|
||||
end if
|
||||
end for
|
||||
return s
|
||||
end function
|
||||
|
||||
function inOrder(sequence s)
|
||||
for i = 1 to length(s)-1 do
|
||||
if compare(s[i],s[i+1]) > 0 then
|
||||
return 0
|
||||
end if
|
||||
end for
|
||||
return 1
|
||||
end function
|
||||
|
||||
function bogosort(sequence s)
|
||||
while not inOrder(s) do
|
||||
? s
|
||||
s = shuffle(s)
|
||||
end while
|
||||
return s
|
||||
end function
|
||||
|
||||
? bogosort(shuffle({1,2,3,4,5,6}))
|
||||
|
|
@ -1,17 +1,15 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
|
||||
with javascript_semantics
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">inOrder</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">==</span><span style="color: #7060A8;">sort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">deep_copy</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- <snigger></span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function inOrder(sequence s)
|
||||
return s==sort(deep_copy(s)) -- <snigger>
|
||||
end function
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">bogosort</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">while</span> <span style="color: #008080;">not</span> <span style="color: #000000;">inOrder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #0000FF;">?</span> <span style="color: #000000;">s</span>
|
||||
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">shuffle</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">s</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
function bogosort(sequence s)
|
||||
while not inOrder(s) do
|
||||
? s
|
||||
s = shuffle(s)
|
||||
end while
|
||||
return s
|
||||
end function
|
||||
|
||||
<span style="color: #0000FF;">?</span> <span style="color: #000000;">bogosort</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shuffle</span><span style="color: #0000FF;">({</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">}))</span>
|
||||
<!--
|
||||
? bogosort(shuffle({1,2,3,4,5,6}))
|
||||
|
|
|
|||
|
|
@ -1,29 +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
|
||||
}
|
||||
|
||||
function isSorted( [Array] $data )
|
||||
{
|
||||
$sorted = $true
|
||||
for( $i = 1; ( $i -lt $data.length ) -and $sorted; $i++ )
|
||||
{
|
||||
$sorted = $data[ $i - 1 ] -le $data[ $i ]
|
||||
}
|
||||
$sorted
|
||||
}
|
||||
|
||||
function BogoSort ( [Array] $indata ) {
|
||||
$data = $indata.Clone()
|
||||
while( -not ( isSorted $data ) ) {
|
||||
$data = shuffle $indata
|
||||
}
|
||||
$data
|
||||
}
|
||||
|
||||
$l = 7; BogoSort ( 1..$l | ForEach-Object { $Rand = New-Object Random }{ $Rand.Next( 0, $l - 1 ) } )
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
sub swap( byref a, byref b )
|
||||
dim tmp
|
||||
tmp = a
|
||||
a = b
|
||||
b = tmp
|
||||
end sub
|
||||
|
||||
'knuth shuffle (I think)
|
||||
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
|
||||
|
||||
function inOrder( a )
|
||||
dim res
|
||||
dim i
|
||||
for i = 0 to ubound( a ) - 1
|
||||
res = ( a(i) <= a(i+1) )
|
||||
if res = false then exit for
|
||||
next
|
||||
inOrder = res
|
||||
end function
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
dim a
|
||||
a = array(11, 1, 2, 3, 4, 4, 6, 7, 8)
|
||||
|
||||
dim t
|
||||
t = timer
|
||||
while not inorder( a )
|
||||
shuffle a
|
||||
wend
|
||||
wscript.echo timer-t, "seconds"
|
||||
wscript.echo join( a, ", " )
|
||||
Loading…
Add table
Add a link
Reference in a new issue