Langton's ant: Difference between revisions
Content added Content deleted
(→{{header|REXX}}: correct chirality and added cropping (to minimize white parts of the plane of cells). ----) |
(→{{header|REXX}}: changed output character (for the black color) to conform to others. ----) |
||
Line 1,746: | Line 1,746: | ||
if dir==0 then dir=4 /*ant should be facing "west". */ |
if dir==0 then dir=4 /*ant should be facing "west". */ |
||
if dir==5 then dir=1 /*and should be facing "north". */ |
if dir==5 then dir=1 /*and should be facing "north". */ |
||
select /*ant walks direction it's facing*/ |
|||
when dir==1 then y=y+1 /*walking north? Then go "up". */ |
|||
when dir==2 then x=x+1 /*walking east? Then go "right"*/ |
|||
when dir==3 then y=y-1 /*walking south? Then go "down".*/ |
|||
when dir==4 then x=x-1 /*walking west? Then go "left".*/ |
|||
end |
|||
end |
end |
||
Line 1,764: | Line 1,764: | ||
end /*above code crops left of array*/ |
end /*above code crops left of array*/ |
||
do y=tb to bb by -1; |
do y=tb to bb by -1; _='' /*display a plane (row) of cells*/ |
||
do x=minx to rb /*process a "row" of cells. */ |
do x=minx to rb /*process a "row" of cells. */ |
||
_=_||@.x.y /*build a cell row for display. */ |
|||
end |
end |
||
_=translate(_,'#',10) /*color the cells: black | white*/ |
|||
if |
if _\='' then say strip(_,'T') /*crop completely white lines. */ |
||
end |
end |
||
</lang> |
</lang> |
||
Output |
Output |
||
<pre style="height: |
<pre style="height:60ex;overflow:scroll"> |
||
──────── Langton's ant walked 11759 steps. ──────── |
──────── Langton's ant walked 11759 steps. ──────── |
||
## |
|||
#### |
|||
# ## # |
|||
## #### |
|||
# # # # |
|||
## # ## |
|||
# # ## |
|||
## # ### |
|||
## # # ### # |
|||
## ## ## # ### |
|||
# # # ## # # # ### # |
|||
### ### # # ## # ### |
|||
# #### ## # # # ### # |
|||
## ## # ### |
|||
## ## ## # # ### # |
|||
#### # ## # ## # ### |
|||
##### ## ### ## ## ## # # ### # |
|||
# # # ## # ## #### ## ## # ### |
|||
#### ### #### #### ## # # # ### # |
|||
### # # ## ## # ## ## # ### |
|||
#### ## ## ## # # # # # # ### # |
|||
# ## # # ## ## # # # ## # ### |
|||
# #### ## # # ######## # # # # # ### # |
|||
## ## # ## # # ## ## # # # ## ## ## # ### |
|||
# # # # # # # # ## ## # ##### # # ### # |
|||
## #### ## # #### # # ## ## # ## # ### |
|||
## ########## ## ##### # #### # # # # ### # |
|||
# # # ## # # # # ## ##### ## # # ## # ### |
|||
# ## # ## # # ##### # ##### # # # ### # |
|||
# ## ### ### # # ## # ## ###### # # ## # ### |
|||
# #### ## # # ### ### ## ## ## # ## # # ### # |
|||
## # ## # ######### ## #### # ## # ### |
|||
# # # #### # ########### ## # # # ### # |
|||
# # #### #### ## # ## ### ## # ### |
|||
# # # # # ## ## # # ### # # # # ### # |
|||
# ## #### #### ##### ## ## # ## # # ### |
|||
## # # ## ### # ### # # ## # ### # |
|||
# # ### ## # ## #### # # # # # ### |
|||
# #### ## # # ### ## ## ## ### # |
|||
# ## ## ### # ## # ### ## # # ### |
|||
## # ## ## # ## ## # # |
|||
## # #### # # # ### ## # # # |
|||
## ### ##### # ## ## ## # # ## # ### # |
|||
# # ### # ###### ## ## #### # ## ### |
|||
# # # ### # #### # # ##### # # |
|||
### ### # # ### ## # ## ### # |
|||
## ## # # # ## #### ## ### # # |
|||
### ## ## # # # # ### |
|||
# ### # # ## ## |
|||
# # # # # # |
|||
# ## ## ### |
|||
## # #### # |
|||
## ############ ## |
|||
</pre> |
</pre> |
||