Anonymous user
Langton's ant: Difference between revisions
→{{header|REXX}}: correct chirality and added cropping (to minimize white parts of the plane of cells). ----
m (→{{header|REXX}}: corrected spelling error (typo) in a comment.) |
(→{{header|REXX}}: correct chirality and added cropping (to minimize white parts of the plane of cells). ----) |
||
Line 1,727:
=={{header|REXX}}==
<lang rexx>
/*Langton's ant*/
parse arg dir . /*allow specification: ant facing*/
/*binary colors: 0=white, 1=black*/
@.=0 /*define stem array (all white).*/
Line 1,733 ⟶ 1,735:
bb= 1 ; tb=100 /*bottom boundry, top boundry.*/
x=(rb-lb)%2 ; y=(tb-bb)%2 /*approximate center (walk start)*/
if dir=='' then dir=random(1,4)
/*1=north 2=east 3=south 4=west*/
Line 1,751 ⟶ 1,753:
end
end
/*───────────────────────────────────────────────display the ant's walk.*/
say "──────── Langton's ant walked" steps 'steps. ────────'
say
do minx=lb to rb /*find the leftest black column.*/
do y=bb to tb /*search row by row for it. */
if @.minx.y then leave minx /*found one, now quit searching.*/
end
end /*above code crops left of array*/
do y=tb to bb by -1; r='' /*display the plane of cells. */
do x=
r=r||@
end
r=translate(r,' █',01) /*color the cells: black | white*/
if r\='' then say strip(r,'T') /*crop
end
</lang>
Output
<pre style="height:50ex;overflow:scroll">
──────── Langton's ant walked
██
████
█ ██ █
██ ████
██
█ █ █ ██
█ ████ ██ █
██ ██ ██
████ █ ██ █
█████ ██ ███ ██ ██
█ █ █ ██ █ ██
████ ███ ████ ████ ██ █
███ █ █ ██ ██
████ ██ ██
█ ██ █ █ ██ ██
█ ████ ██ █ █ ████████ █ █
██ ██ █ ██
█ █ █ █
██ ████ ██ █ ████ █
██ ██████████ ██
█ █ █ ██ █ █
█ ██ █ ██
█ ██ ███ ███ █ █
██ █ ██ █ █████████ ██
█ █ █
█ █ ████ ████
█ █ █ █ █ ██ ██
█ ██ ████ ████ █████ ██
██ █ █ ██ ███ █
█ █ ███ ██ █ ██
█ ████ ██ █ █
█ ██ ██ ███ █
██ █ ██
██ █ ████ █ █ █
██ ███
█
█ █ █ ███ █ ████
███
██ ██ █ █ █ ██ ████
███ ██ ██ █
█ ███ █
█ █ █ █ █ █
█ ██ ██ ███
██ █ ████ █
██ ████████████ ██
</pre>
|