Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
51
Task/Langtons-ant/Ela/langtons-ant-1.ela
Normal file
51
Task/Langtons-ant/Ela/langtons-ant-1.ela
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
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' _ [] = []
|
||||
newfield' n (x::xs)
|
||||
| n == yc = row 0 x :: xs
|
||||
| else = x :: newfield' (n+1) xs
|
||||
where row _ [] = []
|
||||
row n (x::xs)
|
||||
| n == xc = toggle x :: xs
|
||||
| else = x :: row (n+1) xs
|
||||
where toggle White = Black
|
||||
toggle Black = White
|
||||
|
||||
showPath (Field xs) = toString <| show' "" xs
|
||||
where show' sb [] = sb +> ""
|
||||
show' sb (x::xs) = show' (showRow sb x +> "\r\n") xs
|
||||
where showRow sb [] = sb +> ""
|
||||
showRow sb (x::xs) = showRow (sb +> s) xs
|
||||
where s | isBlack x = "#"
|
||||
| else = "_"
|
||||
|
||||
move s xc yc = move' (Fwd,xc,yc) (field s)
|
||||
where move' (pos,xc,yc)@coor fld
|
||||
| xc >= s || yc >= s || xc < 0 || yc < 0 = fld
|
||||
| else = fld |> newfield xc yc |> move' (matrix (dir fld) coor)
|
||||
where dir (Field xs)
|
||||
| `isBlack` (xs:yc):xc = Lft
|
||||
| else = Rgt
|
||||
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
|
||||
right Fwd = Rgt
|
||||
right Rgt = Bwd
|
||||
right Bwd = Lft
|
||||
left Lft = Bwd
|
||||
left Bwd = Rgt
|
||||
left Rgt = Fwd
|
||||
left Fwd = Lft
|
||||
1
Task/Langtons-ant/Ela/langtons-ant-2.ela
Normal file
1
Task/Langtons-ant/Ela/langtons-ant-2.ela
Normal file
|
|
@ -0,0 +1 @@
|
|||
showPath <| move 100 50 50
|
||||
Loading…
Add table
Add a link
Reference in a new issue