Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,94 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
with Ada.Numerics.Discrete_Random;
|
||||
procedure Circle is
|
||||
-- extreme coordinate values are -15:0, 15:0, 0:-15, 0:15
|
||||
subtype Coordinate is Integer range -15 .. 15;
|
||||
type Point is record
|
||||
X, Y : Coordinate;
|
||||
end record;
|
||||
type Point_List is array (Positive range <>) of Point;
|
||||
|
||||
function Acceptable (Position : Point) return Boolean is
|
||||
Squared_Sum : Natural := Position.X ** 2 + Position.Y ** 2;
|
||||
begin
|
||||
return 10 ** 2 <= Squared_Sum and Squared_Sum <= 15 ** 2;
|
||||
end Acceptable;
|
||||
|
||||
-- first algorithm
|
||||
function Generate_Random_Points
|
||||
(Count : Positive := 100)
|
||||
return Point_List
|
||||
is
|
||||
package RNG is new Ada.Numerics.Discrete_Random (Coordinate);
|
||||
Generator : RNG.Generator;
|
||||
Next_Point : Point;
|
||||
Result : Point_List (1 .. Count);
|
||||
begin
|
||||
RNG.Reset (Generator);
|
||||
for N in Result'Range loop
|
||||
loop
|
||||
Next_Point.X := RNG.Random (Generator);
|
||||
Next_Point.Y := RNG.Random (Generator);
|
||||
exit when Acceptable (Next_Point);
|
||||
end loop;
|
||||
Result (N) := Next_Point;
|
||||
end loop;
|
||||
return Result;
|
||||
end Generate_Random_Points;
|
||||
|
||||
-- second algorithm
|
||||
function Choose_Precalculated
|
||||
(Count : Positive := 100)
|
||||
return Point_List
|
||||
is
|
||||
subtype Possible_Points is Positive range 1 .. 404;
|
||||
package RNG is new Ada.Numerics.Discrete_Random (Possible_Points);
|
||||
Generator : RNG.Generator;
|
||||
Point_Pool : Point_List (Possible_Points);
|
||||
Next_Point : Point;
|
||||
Next_Index : Possible_Points := 1;
|
||||
Result : Point_List (1 .. Count);
|
||||
begin
|
||||
-- precalculate
|
||||
Precalculate : for X in Coordinate'Range loop
|
||||
Next_Point.X := X;
|
||||
for Y in Coordinate'Range loop
|
||||
Next_Point.Y := Y;
|
||||
if Acceptable (Next_Point) then
|
||||
Point_Pool (Next_Index) := Next_Point;
|
||||
exit Precalculate when Next_Index = Possible_Points'Last;
|
||||
Next_Index := Next_Index + 1;
|
||||
end if;
|
||||
end loop;
|
||||
end loop Precalculate;
|
||||
-- choose
|
||||
RNG.Reset (Generator);
|
||||
for N in Result'Range loop
|
||||
Result (N) := Point_Pool (RNG.Random (Generator));
|
||||
end loop;
|
||||
return Result;
|
||||
end Choose_Precalculated;
|
||||
|
||||
procedure Print_Points (Points : Point_List) is
|
||||
Output_String : array (Coordinate, Coordinate) of Character :=
|
||||
(others => (others => ' '));
|
||||
begin
|
||||
for N in Points'Range loop
|
||||
Output_String (Points (N).X, Points (N).Y) := '*';
|
||||
end loop;
|
||||
for Line in Output_String'Range (2) loop
|
||||
for Column in Output_String'Range (1) loop
|
||||
Ada.Text_IO.Put (Output_String (Column, Line));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
end Print_Points;
|
||||
|
||||
My_Circle_Randomly : Point_List := Generate_Random_Points;
|
||||
My_Circle_Precalculated : Point_List := Choose_Precalculated;
|
||||
begin
|
||||
Ada.Text_IO.Put_Line ("Randomly generated:");
|
||||
Print_Points (My_Circle_Randomly);
|
||||
Ada.Text_IO.Put_Line ("Chosen from precalculated:");
|
||||
Print_Points (My_Circle_Precalculated);
|
||||
end Circle;
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
identification division.
|
||||
program-id. circle.
|
||||
environment division.
|
||||
input-output section.
|
||||
file-control.
|
||||
select plot-file assign "circle.txt".
|
||||
data division.
|
||||
file section.
|
||||
fd plot-file report plot.
|
||||
working-storage section.
|
||||
1 binary.
|
||||
2 seed pic 9(18).
|
||||
2 x pic s9(4).
|
||||
2 y pic s9(4).
|
||||
2 i pic 9(4).
|
||||
2 dot-count pic 9(4) value 0.
|
||||
2 dot-count-save pic 9(4) value 0.
|
||||
2 temp-points.
|
||||
3 pic s9(4) occurs 2.
|
||||
2 xy-table.
|
||||
3 point-pair occurs 0 to 404 depending dot-count.
|
||||
4 x-point pic s9(4).
|
||||
4 y-point pic s9(4).
|
||||
1 plot-table value all "0".
|
||||
2 occurs 31.
|
||||
3 dot pic 9 occurs 31.
|
||||
1 cur-date-time.
|
||||
2 yyyymmdd pic 9(8).
|
||||
2 hh pic 9(2).
|
||||
2 mm pic 9(2).
|
||||
2 ss pic 9(2).
|
||||
1 plot-work.
|
||||
2 plot-item pic xb occurs 31.
|
||||
report section.
|
||||
rd plot.
|
||||
1 plot-line type de.
|
||||
2 line plus 1.
|
||||
3 column is 1 source is plot-work pic x(62).
|
||||
procedure division.
|
||||
begin.
|
||||
perform compute-seed
|
||||
perform find-all-valid-points
|
||||
perform shuffle-point-pairs
|
||||
perform select-100-dots
|
||||
perform print-dots
|
||||
stop run
|
||||
.
|
||||
|
||||
find-all-valid-points.
|
||||
perform varying x from -15 by 1 until x > +15
|
||||
perform varying y from -15 by 1 until y > +15
|
||||
if (function sqrt (x ** 2 + y ** 2))
|
||||
>= 10 and <= 15
|
||||
then
|
||||
move 1 to dot (x + 16 y + 16)
|
||||
add 1 to dot-count
|
||||
compute x-point (dot-count) = x + 16
|
||||
compute y-point (dot-count) = y + 16
|
||||
end-if
|
||||
end-perform
|
||||
end-perform
|
||||
display "Total points: " dot-count
|
||||
.
|
||||
|
||||
shuffle-point-pairs.
|
||||
move dot-count to dot-count-save
|
||||
compute i = function random (seed) * dot-count + 1
|
||||
perform varying dot-count from dot-count by -1
|
||||
until dot-count < 2
|
||||
move point-pair (i) to temp-points
|
||||
move point-pair (dot-count) to point-pair (i)
|
||||
move temp-points to point-pair (dot-count)
|
||||
compute i = function random * dot-count + 1
|
||||
end-perform
|
||||
move dot-count-save to dot-count
|
||||
.
|
||||
|
||||
select-100-dots.
|
||||
perform varying i from 1 by 1
|
||||
until i > 100
|
||||
compute x = x-point (i)
|
||||
compute y = y-point (i)
|
||||
move 2 to dot (x y)
|
||||
end-perform
|
||||
.
|
||||
|
||||
print-dots.
|
||||
open output plot-file
|
||||
initiate plot
|
||||
perform varying y from 1 by 1 until y > 31
|
||||
move spaces to plot-work
|
||||
perform varying x from 1 by 1 until x > 31
|
||||
if dot (x y) = 2
|
||||
move "o" to plot-item (x)
|
||||
end-if
|
||||
end-perform
|
||||
generate plot-line
|
||||
end-perform
|
||||
terminate plot
|
||||
close plot-file
|
||||
.
|
||||
|
||||
compute-seed.
|
||||
unstring function current-date into
|
||||
yyyymmdd hh mm ss
|
||||
compute seed =
|
||||
(function integer-of-date (yyyymmdd) * 86400)
|
||||
compute seed = seed
|
||||
+ (hh * 3600) + (mm * 60) + ss
|
||||
compute seed = function mod (seed 32768)
|
||||
.
|
||||
|
||||
end program circle.
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
include std/console.e
|
||||
|
||||
sequence validpoints = {}
|
||||
sequence discardedpoints = {}
|
||||
sequence rand100points = {}
|
||||
atom coordresult
|
||||
integer randindex
|
||||
|
||||
--scan for all possible values. store discarded ones in another sequence, for extra reference.
|
||||
for y = -15 to 15 do
|
||||
for x = -15 to 15 do
|
||||
|
||||
coordresult = sqrt( x * x + y * y )
|
||||
|
||||
if coordresult >= 10 and coordresult <= 15 then --if it would fall in the ring area
|
||||
validpoints &= {{x, y, coordresult}} --concatenate (add to the end) the coordinate pair x, y and the
|
||||
-- result into a subsequence of sequence validpoints
|
||||
else
|
||||
discardedpoints &= {{x, y, coordresult}} --else put it in the discarded sequence
|
||||
end if
|
||||
|
||||
end for
|
||||
end for
|
||||
|
||||
for i = 1 to 100 label "oneofhundred" do --make 100 random coordinate pairs
|
||||
randindex = rand(length(validpoints) ) --random value from 1 to the number of 3 value subsequences in validpoints (the data)
|
||||
|
||||
if length(rand100points) = 0 then --if rand100points sequence is empty, add the first subsequence to it.
|
||||
rand100points &= {validpoints[randindex]}
|
||||
|
||||
else --if it isn't empty, then..
|
||||
for j = 1 to length(rand100points) do --loop through each "data chunk" in rand100points
|
||||
|
||||
if equal(validpoints[randindex], rand100points[j]) = 1 then --if any are the same as the randomly chosen chunk in
|
||||
retry "oneofhundred" -- validpoints, then retry from one line below the "oneofhundred" loop without incrementing i.
|
||||
end if --the continue keyword would increment i instead.
|
||||
|
||||
end for
|
||||
|
||||
rand100points &= {validpoints[randindex]} --length of rand100points isnt 0 and no data chunks match ones that the program
|
||||
--already picked before, so add this subsequence chunk to rand100points.
|
||||
end if
|
||||
|
||||
end for
|
||||
|
||||
for i = 1 to 32 do --32 lines
|
||||
printf(1,"\n")
|
||||
for j = 1 to 32 label "xscan" do --32 characters on each line
|
||||
|
||||
for k = 1 to length(rand100points) do --for every subsequence in this
|
||||
if rand100points[k][1]+16 = j and rand100points[k][2]+16 = i then --if the x and y coordinates in the picked points
|
||||
printf(1, 178) --(adjusted to minimum of 1,1) are at the same place as in the console output grid
|
||||
continue "xscan" --print a funny character and continue to the next "xscan"
|
||||
end if
|
||||
end for
|
||||
|
||||
printf(1, 176) --if no picked points were there, print another funny character to represent a blank space
|
||||
|
||||
end for
|
||||
end for
|
||||
|
||||
printf(1, "\nNumber of valid coordinate pairs %d :", length(validpoints) )
|
||||
printf(1, "\nNumber of discarded coordinate pairs : %d", length(discardedpoints) )
|
||||
printf(1, "\nNumber of randomly picked coordinate pairs : %d\n", length(rand100points) )
|
||||
any_key()
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
for i = 1 to length(validpoints) do --simple each pixel output to screen surface
|
||||
dummy=pixelColor(surface,validpoints[i][1]+18,validpoints[i][2]+18,#AA0202FF) --i is index number of each subsequence 'chunk'.
|
||||
--index 1 is x, index 2 is y, inside that chunk.
|
||||
end for
|
||||
|
||||
for i = 1 to length(discardedpoints) do
|
||||
dummy=pixelColor(surface,discardedpoints[i][1]+18,discardedpoints[i][2]+52,#0202AAFF)
|
||||
end for
|
||||
|
||||
for i = 1 to length(rand100points) do
|
||||
dummy=pixelColor(surface,rand100points[i][1]+55,rand100points[i][2]+52,#02AA02FF)
|
||||
end for
|
||||
|
||||
dummy=boxColor(surface,0,71,395,111,#232323FF) --background box
|
||||
dummy=stringColor(surface,0,73,sprintf("Number of valid coordinate pairs %d :", length(validpoints) ),#AA0202FF)
|
||||
|
||||
dummy=stringColor(surface,0,83,sprintf("Number of discarded coordinate pairs : %d", length(discardedpoints) ),#0202AAFF)
|
||||
|
||||
dummy=stringColor(surface,0,93,sprintf("Number of randomly picked coordinate pairs : %d", length(rand100points) ),#02AA02FF)
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
$MinR2 = 10 * 10
|
||||
$MaxR2 = 15 * 15
|
||||
|
||||
$Points = @{}
|
||||
|
||||
While ( $Points.Count -lt 100 )
|
||||
{
|
||||
$X = Get-Random -Minimum -16 -Maximum 17
|
||||
$Y = Get-Random -Minimum -16 -Maximum 17
|
||||
$R2 = $X * $X + $Y * $Y
|
||||
|
||||
If ( $R2 -ge $MinR2 -and $R2 -le $MaxR2 -and "$X,$Y" -notin $Points.Keys )
|
||||
{
|
||||
$Points += @{ "$X,$Y" = 1 }
|
||||
}
|
||||
}
|
||||
|
||||
ForEach ( $Y in -16..16 ) { ( -16..16 | ForEach { ( " ", "*" )[[int]$Points["$_,$Y"]] } ) -join '' }
|
||||
Loading…
Add table
Add a link
Reference in a new issue