Jump to content

Langton's ant: Difference between revisions

m (→‎{{header|REXX}}: added a comment in the section header about the REXX program's output justification of the ant's walk field. -- ~~~~)
Line 783:
 
<lang ela>open list core generic
 
type Field = Field a
type Color = White | Black
type Direction = Lft | Fwd | Rgt | Bwd
field s = Field [[White \\ _ <- [1..s]] \\ _ <- [1..s]]
 
isBlack Black = true
isBlack _ = false
 
newfield xc yc (Field xs) = Field (newfield' 0 xs)
where newfield' _ [] = []
Line 804:
toggle Black = White
showPath (Field xs) = toString <| show' stringBuilder"" xs
where show' sb [] = sb +> ""
show' sb (x::xs) = show' (showRow sb x +> "\r\n") xs
Line 814:
move s xc yc = move' (Fwd,xc,yc) (field s)
where move' (pos,xc,yc)@coor fld
| xc >= s or|| yc >= s or|| xc < 0 or|| yc < 0 = fld
| else = fld |> newfield xc yc |> move' (matrix (dir fld) coor)
where dir (Field xs)
Line 821:
matrix Lft (pos,x,y) = go (left pos,x,y)
matrix Rgt (pos,x,y) = go (right pos,x,y)
go (Lft,x,y) = (Lft,x - 1,y)
go (Rgt,x,y) = (Rgt,x+1,y)
go (Fwd,x,y) = (Fwd,x,y - 1)
go (Bwd,x,y) = (Bwd,x,y+1)
right Lft = Fwd
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.