Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,56 +0,0 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Langtons_Ant is
|
||||
|
||||
Size: constant Positive := 100; -- change this to extend the playground
|
||||
|
||||
subtype Step is Integer range -1 .. +1;
|
||||
|
||||
procedure Right(N, W: in out Step) is
|
||||
Tmp: Step := W;
|
||||
begin
|
||||
W := - N;
|
||||
N := Tmp;
|
||||
end Right;
|
||||
|
||||
procedure Left(N, W: in out Step) is
|
||||
begin
|
||||
for I in 1 .. 3 loop
|
||||
Right(N, W);
|
||||
end loop;
|
||||
end Left;
|
||||
|
||||
Color_Character: array(Boolean) of Character :=
|
||||
(False => ' ', True => '#');
|
||||
|
||||
Is_Black: array (1 .. Size, 1 .. Size) of Boolean :=
|
||||
(others => (others => False)); -- initially, the world is white;
|
||||
|
||||
Ant_X, Ant_Y: Natural := Size/2; -- Position of Ant;
|
||||
Ant_North: Step := 1; Ant_West: Step := 0; -- initially, Ant looks northward
|
||||
|
||||
Iteration: Positive := 1;
|
||||
|
||||
begin
|
||||
loop -- iterate the loop until an exception is raised
|
||||
if Is_Black(Ant_X, Ant_Y) then
|
||||
Left(Ant_North, Ant_West);
|
||||
else
|
||||
Right(Ant_North, Ant_West);
|
||||
end if;
|
||||
Is_Black(Ant_X, Ant_Y) := not Is_Black(Ant_X, Ant_Y);
|
||||
Ant_X := Ant_X - Ant_North; -- this may raise an exception
|
||||
Ant_Y := Ant_Y - Ant_West; -- this may raise an exception
|
||||
Iteration := Iteration + 1;
|
||||
end loop;
|
||||
|
||||
exception
|
||||
when Constraint_Error => -- Ant has left its playground ... now output
|
||||
for X in 1 .. Size loop
|
||||
for Y in 1 .. Size loop
|
||||
Ada.Text_IO.Put(Color_Character(Is_Black(X, Y)));
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
end loop;
|
||||
Ada.Text_IO.Put_Line("# Iteration:" & Integer'Image(Iteration));
|
||||
end Langtons_Ant;
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
Global $iCountMax = 100000
|
||||
Global $aFields[100][100][2]
|
||||
Global $iDelayStep = 10 ; stop between steps in msec
|
||||
|
||||
Global $aDirection[4][4] = [ _ ; [ direction 0-3 ][ left change x, y, right change x, y ]
|
||||
[-1, 0, +1, 0], _ ; == direction 0
|
||||
[ 0, -1, 0, +1], _ ; == direction 1
|
||||
[+1, 0, -1, 0], _ ; == direction 2
|
||||
[ 0, +1, 0, -1]] ; == direction 3
|
||||
|
||||
Global $hGui = GUICreate("Langton's ant", 100*8, 100*8)
|
||||
GUISetBkColor(0xFFFFFF)
|
||||
|
||||
For $i = 0 To 99
|
||||
For $j = 0 To 99
|
||||
$aFields[$i][$j][0] = GUICtrlCreateLabel('', $j*8, $i*8)
|
||||
GUICtrlSetColor(-1, 0xFF0000)
|
||||
$aFields[$i][$j][1] = 0
|
||||
Next
|
||||
Next
|
||||
|
||||
GUISetState()
|
||||
|
||||
GUICtrlSetData($aFields[49][49][0], '#')
|
||||
|
||||
Do
|
||||
Sleep($iDelayStep)
|
||||
Until Not _SetAnt()
|
||||
|
||||
Do
|
||||
Until GUIGetMsg() = -3
|
||||
|
||||
|
||||
Func _SetAnt()
|
||||
Local Static $iRowLast = 49, $iColLast = 49, $iCount = 0
|
||||
Local Static $aCol[2] = [0xFFFFFF,0x000000], $iDirection = 0
|
||||
Local $iRow, $iCol, $fRight = False
|
||||
If $iCount = $iCountMax Then Return 0
|
||||
|
||||
; == get current color
|
||||
Local $iLastColor = $aFields[$iRowLast][$iColLast][1]
|
||||
|
||||
; == go to left/right
|
||||
If $iLastColor = 0 Then $fRight = True
|
||||
|
||||
; == set the ant to the next field
|
||||
Local $indexX = 0, $indexY = 1
|
||||
If $fRight Then
|
||||
$indexX = 2
|
||||
$indexY = 3
|
||||
EndIf
|
||||
$iRow = $iRowLast + ($aDirection[$iDirection][$indexX])
|
||||
$iCol = $iColLast + ($aDirection[$iDirection][$indexY])
|
||||
If $iRow < 0 Or $iRow > 99 Or $iCol < 0 Or $iCol > 99 Then Return 0
|
||||
GUICtrlSetData($aFields[$iRowLast][$iColLast][0], '')
|
||||
GUICtrlSetData($aFields[$iRow][$iCol][0], '#')
|
||||
|
||||
; == direction for next step
|
||||
If $fRight Then
|
||||
$iDirection += 1
|
||||
If $iDirection = 4 Then $iDirection = 0
|
||||
Else
|
||||
$iDirection -= 1
|
||||
If $iDirection = -1 Then $iDirection = 3
|
||||
EndIf
|
||||
|
||||
; == change the color of the current field
|
||||
GUICtrlSetBkColor($aFields[$iRowLast][$iColLast][0], $aCol[(Not $iLastColor)*1])
|
||||
$aFields[$iRowLast][$iColLast][1] = (Not $iLastColor)*1
|
||||
|
||||
$iRowLast = $iRow
|
||||
$iColLast = $iCol
|
||||
$iCount += 1
|
||||
WinSetTitle($hGui, '', "Langton's ant [ step: " & StringFormat('%06d', $iCount) & " ]")
|
||||
Return 1
|
||||
EndFunc ;==>_SetAnt
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. langtons-ant.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
78 Grid-Size VALUE 100.
|
||||
01 grid-area.
|
||||
03 grid-x OCCURS Grid-Size TIMES.
|
||||
05 grid-y OCCURS Grid-Size TIMES.
|
||||
07 cell-colour PIC X VALUE "W".
|
||||
88 black VALUE "B".
|
||||
88 white VALUE "W".
|
||||
|
||||
01 ant-x PIC 999.
|
||||
01 ant-y PIC 999.
|
||||
|
||||
01 ant-direction PIC 9.
|
||||
88 upward VALUE 0.
|
||||
88 rightward VALUE 1.
|
||||
88 downward VALUE 2.
|
||||
88 leftward VALUE 3.
|
||||
|
||||
78 Pause-Time-Ns VALUE 10000000.
|
||||
|
||||
01 display-y PIC 999.
|
||||
|
||||
78 Black-Background VALUE 0.
|
||||
78 White-Background VALUE 7.
|
||||
|
||||
01 i PIC 999.
|
||||
01 j PIC 999.
|
||||
|
||||
01 pause PIC X.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
main-line.
|
||||
DIVIDE Grid-Size BY 2 GIVING ant-x, ant-y
|
||||
|
||||
PERFORM display-initial-grid
|
||||
PERFORM UNTIL (ant-x = Grid-Size OR 0)
|
||||
OR (ant-y = Grid-Size OR 0)
|
||||
PERFORM step-simulation
|
||||
CALL "CBL_OC_NANOSLEEP" USING Pause-Time-Ns
|
||||
END-PERFORM
|
||||
|
||||
DISPLAY "Press enter to quit." AT LINE 1 COLUMN 1
|
||||
ACCEPT pause
|
||||
|
||||
GOBACK
|
||||
.
|
||||
step-simulation.
|
||||
IF black (ant-x, ant-y)
|
||||
SET white (ant-x, ant-y) TO TRUE
|
||||
PERFORM display-ant-cell
|
||||
COMPUTE ant-direction =
|
||||
FUNCTION MOD(ant-direction + 1, 4)
|
||||
ELSE
|
||||
SET black (ant-x, ant-y) TO TRUE
|
||||
PERFORM display-ant-cell
|
||||
COMPUTE ant-direction =
|
||||
FUNCTION MOD(ant-direction - 1, 4)
|
||||
END-IF
|
||||
|
||||
EVALUATE TRUE
|
||||
WHEN upward
|
||||
ADD 1 TO ant-y
|
||||
WHEN rightward
|
||||
ADD 1 TO ant-x
|
||||
WHEN downward
|
||||
SUBTRACT 1 FROM ant-y
|
||||
WHEN leftward
|
||||
SUBTRACT 1 FROM ant-x
|
||||
END-EVALUATE
|
||||
.
|
||||
display-ant-cell.
|
||||
SUBTRACT ant-y FROM Grid-Size GIVING display-y
|
||||
IF black (ant-x, ant-y)
|
||||
DISPLAY SPACE AT LINE display-y COLUMN ant-x
|
||||
WITH BACKGROUND-COLOR Black-Background
|
||||
ELSE
|
||||
DISPLAY SPACE AT LINE display-y COLUMN ant-x
|
||||
WITH BACKGROUND-COLOR White-Background
|
||||
END-IF
|
||||
.
|
||||
display-initial-grid.
|
||||
PERFORM VARYING i FROM 1 BY 1 UNTIL i > Grid-Size
|
||||
AFTER j FROM 1 BY 1 UNTIL j > Grid-Size
|
||||
DISPLAY SPACE AT LINE i COLUMN j
|
||||
WITH BACKGROUND-COLOR White-Background
|
||||
END-PERFORM
|
||||
.
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
config const gridHeight: int = 100;
|
||||
config const gridWidth: int = 100;
|
||||
|
||||
class PBMWriter {
|
||||
var imgDomain: domain(2);
|
||||
var imgData: [imgDomain] int;
|
||||
|
||||
proc PBMWriter( height: int, width: int ){
|
||||
imgDomain = { 1..#height, 1..#width };
|
||||
}
|
||||
|
||||
proc this( i : int, j : int) ref : int{
|
||||
return this.imgData[ i, j ];
|
||||
}
|
||||
|
||||
proc writeImage( fileName: string ){
|
||||
var file = open(fileName, iomode.cw);
|
||||
var writingChannel = file.writer();
|
||||
writingChannel.write("P1\n", imgDomain.dim(1).size, " " ,imgDomain.dim(2).size,"\n");
|
||||
|
||||
for px in imgData {
|
||||
writingChannel.write( px, " " );
|
||||
}
|
||||
|
||||
writingChannel.write( "\n" );
|
||||
writingChannel.flush();
|
||||
writingChannel.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum Color { white, black };
|
||||
|
||||
inline proc nextDirection( position: 2*int, turnLeft: bool ): 2*int {
|
||||
return ( (if turnLeft then 1 else -1 ) * position[2], (if turnLeft then -1 else 1 ) * position[1] );
|
||||
}
|
||||
|
||||
proc <( left: 2*int, right: 2*int ){
|
||||
return left[1] < right[1] && left[2] < right[2];
|
||||
}
|
||||
|
||||
proc <=( left: 2*int, right: 2*int ){
|
||||
return left[1] <= right[1] && left[2] <= right[2];
|
||||
}
|
||||
|
||||
proc main{
|
||||
const gridDomain: domain(2) = {1..#gridHeight, 1..#gridWidth};
|
||||
var grid: [gridDomain] Color;
|
||||
|
||||
var antPos = ( gridHeight / 2, gridWidth / 2 );
|
||||
var antDir = (1,0); // start up;
|
||||
|
||||
while (0,0) < antPos && antPos <= (gridHeight, gridWidth ) {
|
||||
var currColor = grid[ antPos ];
|
||||
grid[antPos] = if currColor == Color.white then Color.black else Color.white ;
|
||||
|
||||
antDir = nextDirection( antDir, currColor == Color.black );
|
||||
antPos = antPos + antDir;
|
||||
}
|
||||
|
||||
var image = new PBMWriter( height = gridHeight, width = gridWidth );
|
||||
|
||||
for (i, j) in gridDomain {
|
||||
image[i,j] = if grid[gridHeight-j+1,gridHeight-i+1] == Color.black then 0 else 1;
|
||||
}
|
||||
|
||||
image.writeImage( "output.png" );
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
include std\console.e
|
||||
include std\graphics.e
|
||||
|
||||
sequence grid = repeat(repeat(1,100),100) --fill 100 by 100 grid with white (1)
|
||||
sequence antData = {48, 53, 360} --ant x coordinate, y coordinate, facing angle
|
||||
integer iterations = 0
|
||||
|
||||
--while ant isn't out of bounds of the 100 by 100 area..
|
||||
while antData[1] > 0 and antData[1] < 100 and antData[2] > 0 and antData[2] < 100 do
|
||||
switch grid[antData[1]][antData[2]] do
|
||||
case 1 then--cell is already white
|
||||
grid[antData[1]][antData[2]] = 0 --cell turns black, ant turns right
|
||||
antData[3] += 90
|
||||
break
|
||||
case 0 then--cell is already black
|
||||
grid[antData[1]][antData[2]] = 1 --cell turns white, ant turns left
|
||||
antData[3] -= 90
|
||||
break
|
||||
end switch
|
||||
--wrap ant directions if > 360 or < 90 (by 90)
|
||||
switch antData[3] do
|
||||
case 450 then
|
||||
antData[3] = 90
|
||||
break
|
||||
case 0 then
|
||||
antData[3] = 360
|
||||
break
|
||||
end switch
|
||||
--move ant based on its new facing, one square
|
||||
--first north, then south, east, west
|
||||
switch antData[3] do
|
||||
case 360 then
|
||||
antData[2] -= 1
|
||||
break
|
||||
case 180 then
|
||||
antData[2] += 1
|
||||
break
|
||||
case 90 then
|
||||
antData[1] += 1
|
||||
break
|
||||
case 270 then
|
||||
antData[1] -= 1
|
||||
break
|
||||
end switch
|
||||
iterations += 1
|
||||
end while
|
||||
|
||||
wrap(0) --don't wrap text output, the grid wouldnt display as a square
|
||||
|
||||
for y=1 to 100 do
|
||||
printf(1,"\n")
|
||||
for x=1 to 100 do
|
||||
switch grid[x][y] do--each grid block , based on color
|
||||
case 0 then
|
||||
printf(1,".")
|
||||
break
|
||||
case 1 then
|
||||
printf(1,"#")
|
||||
break
|
||||
end switch
|
||||
end for
|
||||
end for
|
||||
|
||||
printf(1,"\n%d Iterations\n",iterations)
|
||||
any_key()--wait for keypress, put default message 'press any key..'
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
sequence grid = repeat(repeat(1,100),100) --fill 100 by 100 grid with white (1)
|
||||
sequence antData = {48, 53, 360} --x coordinate, y coordinate, facing angle
|
||||
|
|
@ -1,17 +1,15 @@
|
|||
(phixonline)-->
|
||||
<span style="color: #004080;">sequence</span> <span style="color: #000000;">grid</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">100</span><span style="color: #0000FF;">),</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">aX</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">50</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">aY</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">50</span><span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">gXY</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">angle</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span> <span style="color: #000080;font-style:italic;">-- ' '/'#'; 0,1,2,3 = NESW</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">dX</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">}</span> <span style="color: #000080;font-style:italic;">-- (dY = reverse(dX))</span>
|
||||
sequence grid = repeat(repeat(' ',100),100)
|
||||
integer aX = 50, aY = 50,
|
||||
gXY, angle = 1 -- ' '/'#'; 0,1,2,3 = NESW
|
||||
constant dX = {0,-1,0,1} -- (dY = reverse(dX))
|
||||
|
||||
<span style="color: #008080;">while</span> <span style="color: #000000;">aX</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">aX</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">100</span>
|
||||
<span style="color: #008080;">and</span> <span style="color: #000000;">aY</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">1</span> <span style="color: #008080;">and</span> <span style="color: #000000;">aY</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">100</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">gXY</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">aX</span><span style="color: #0000FF;">][</span><span style="color: #000000;">aY</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">grid</span><span style="color: #0000FF;">[</span><span style="color: #000000;">aX</span><span style="color: #0000FF;">][</span><span style="color: #000000;">aY</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">67</span><span style="color: #0000FF;">-</span><span style="color: #000000;">gXY</span> <span style="color: #000080;font-style:italic;">-- ' '<=>'#', aka 32<->35</span>
|
||||
<span style="color: #000000;">angle</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mod</span><span style="color: #0000FF;">(</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">+</span><span style="color: #000000;">2</span><span style="color: #0000FF;">*</span><span style="color: #000000;">gXY</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: #000080;font-style:italic;">-- +/-1, ie 0,1,2,3 -> 1,2,3,0 or 3,0,1,2</span>
|
||||
<span style="color: #000000;">aX</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">dX</span><span style="color: #0000FF;">[</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #000000;">aY</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">dX</span><span style="color: #0000FF;">[</span><span style="color: #000000;">4</span><span style="color: #0000FF;">-</span><span style="color: #000000;">angle</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
|
||||
while aX>=1 and aX<=100
|
||||
and aY>=1 and aY<=100 do
|
||||
gXY = grid[aX][aY]
|
||||
grid[aX][aY] = 67-gXY -- ' '<=>'#', aka 32<->35
|
||||
angle = mod(angle+2*gXY+3,4) -- +/-1, ie 0,1,2,3 -> 1,2,3,0 or 3,0,1,2
|
||||
aX += dX[angle+1]
|
||||
aY += dX[4-angle]
|
||||
end while
|
||||
|
||||
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">grid</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">))</span>
|
||||
<!--
|
||||
puts(1,join(grid,"\n"))
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
$Size = 100
|
||||
|
||||
$G = @()
|
||||
1..$Size | ForEach { $G += ,( @( 1 ) * $Size ) }
|
||||
|
||||
$x = $y = $Size / 2
|
||||
|
||||
# Direction of next move
|
||||
$Dx = 1
|
||||
$Dy = 0
|
||||
|
||||
# While we are still on the grid...
|
||||
While ( $x -ge 0 -and $y -ge 0 -and $x -lt $Size -and $y -lt $Size )
|
||||
{
|
||||
# Change direction
|
||||
$Dx, $Dy = ( $Dy * $G[$x][$y] ), -( $Dx * $G[$x][$y] )
|
||||
|
||||
# Change state of current square
|
||||
$G[$x][$y] = -$G[$x][$y]
|
||||
|
||||
# Move forward
|
||||
$x += $Dx
|
||||
$y += $Dy
|
||||
}
|
||||
|
||||
# Convert to strings for output
|
||||
ForEach ( $Row in $G ) { ( $Row | ForEach { ( ' ', '', '#')[$_+1] } ) -join '' }
|
||||
|
|
@ -4,9 +4,8 @@ N ← 100
|
|||
# initialise dir pos map
|
||||
[¯1 0] [50 50] ↯N_N 1
|
||||
# Run until out of bounds
|
||||
⍢(
|
||||
⊙(⟜(⍜⊡(-:1)))
|
||||
⟨⍜(⊡1|¯)⇌|⇌⍜(⊡1|¯)⟩:⊙(⊡,,)
|
||||
⍢(⊙⟜⍜⊡¬
|
||||
˜⨬(⍜⊡₁¯⇌|⇌⍜⊡₁¯)⊙◡⊡
|
||||
⟜+
|
||||
| ≥0⋅/↧
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue