Langton's ant: Difference between revisions

1,844 bytes removed ,  12 years ago
→‎{{header|REXX}}: changed output character (for the black color) to conform to others. ----
(→‎{{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:
if dir==0 then dir=4 /*ant should be facing "west". */
if dir==5 then dir=1 /*and should be facing "north". */
select 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
 
Line 1,764:
end /*above code crops left of array*/
 
do y=tb to bb by -1; r_='' /*display thea plane (row) of cells. */
do x=minx to rb /*process a "row" of cells. */
r_=r_||@.x.y /*build a cell row for display. */
end
r_=translate(r_,'#',0110) /*color the cells: black | white*/
if r_\='' then say strip(r_,'T') /*crop completely white rowslines. */
end
</lang>
Output
<pre style="height:50ex60ex;overflow:scroll">
──────── Langton's ant walked 11759 steps. ────────
 
██##
████####
# ██## #
██## ████####
# # # #
██## # ██##
# # ██##
██## # ███###
██## # # ███### #
██## ██## ██## # ███###
# # # ██## # # # ███### #
███### ███### # # ██## # ███###
# ████#### ██## # # # ███### #
██## ██## # ███###
██## ██## ██## # # ███### #
████#### # ██## # ██## # ███###
█████##### ██## ███### ██## ██## ██## # # ███### #
# # # ██## # ██## ████#### ██## ██## # ███###
████#### ███### ████#### ████#### ██## # # # ███### #
███### # # ██## ██## # ██## ██## # ███###
████#### ██## ██## ██## # # # # # # ███### #
# ██## # # ██## ██## # # # ██## # ███###
# ████#### ██## # # ████████######## # # # # # ███### #
██## ██## # ██## # # ██## ██## # # # ██## ██## ██## # ███###
# # # # # # # # ██## ██## # █████##### # # ███### #
██## ████#### ██## # ████#### # # ██## ██## # ██## # ███###
██## ██████████########## ██## █████##### # ████#### # # # # ███### #
# # # ██## # # # # ██## █████##### ██## # # ██## # ███###
# ██## # ██## # # █████##### # █████##### # # # ███### #
# ██## ███### ███### # # ██## # ██## ██████###### # # ██## # ███###
# ████#### ██## # # ███### ███### ██## ██## ██## # ██## # # ███### #
██## # ██## # █████████######### ██## ████#### # ██## # ███###
# # # ████#### # ███████████########### ██## # # # ███### #
# # ████#### ████#### ██## # ██## ███### ██## # ███###
# # # # # ██## ██## # # ███### # # # # ███### #
# ██## ████#### ████#### █████##### ██## ██## # ██## # # ███###
██## # # ██## ███### # ███### # # ██## # ███### #
# # ███### ██## # ██## ████#### # # # # # ███###
# ████#### ██## # # ███### ██## ██## ██## ███### #
# ██## ██## ███### # ██## # ███### ██## # # ███###
██## # ██## ██## # ██## ██## # #
██## # ████#### # # # ███### ██## # # #
██## ███### █████##### # ██## ██## ██## # # ██## # ███### #
# # ███### # ██████###### ██## ██## ████#### # ██## ███###
# # # ███### # ████#### # # █████##### # #
███### ███### # # ███### ██## # ██## ███### #
██## ██## # # # ██## ████#### ██## ███### # #
███### ██## ██## # # # # ███###
# ███### # # ██## ██##
# # # # # #
# ██## ██## ███###
██## # ████#### #
██## ████████████############ ██##
</pre>