Langton's ant: Difference between revisions

Content added Content deleted
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: Line 1,727:


=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*Langton's ant*/
<lang rexx>
/*Langton's ant*/
parse arg dir . /*allow specification: ant facing*/
/*binary colors: 0=white, 1=black*/
/*binary colors: 0=white, 1=black*/
@.=0 /*define stem array (all white).*/
@.=0 /*define stem array (all white).*/
Line 1,733: Line 1,735:
bb= 1 ; tb=100 /*bottom boundry, top boundry.*/
bb= 1 ; tb=100 /*bottom boundry, top boundry.*/
x=(rb-lb)%2 ; y=(tb-bb)%2 /*approximate center (walk start)*/
x=(rb-lb)%2 ; y=(tb-bb)%2 /*approximate center (walk start)*/
dir=random(1,4) /*ant is facing random direction,*/
if dir=='' then dir=random(1,4) /*ant is facing random direction,*/
/*1=north 2=east 3=south 4=west*/
/*1=north 2=east 3=south 4=west*/


Line 1,751: Line 1,753:
end
end
end
end



/*───────────────────────────────────────────────display the ant's walk.*/
/*───────────────────────────────────────────────display the ant's walk.*/
say "──────── Langton's ant walked" steps 'steps. ────────'
say "──────── Langton's ant walked" steps 'steps. ────────'
say
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 y=tb to bb by -1; r='' /*display the plane of cells. */
do x=lb to rb /*process a "row" of cells. */
do x=minx to rb /*process a "row" of cells. */
r=r||@.y.x /*build a cell row for display. */
r=r||@.x.y /*build a cell row for display. */
end
end
r=translate(r,' █',01) /*color the cells: black | white*/
r=translate(r,' █',01) /*color the cells: black | white*/
if r\='' then say strip(r,'T') /*crop blank parts of the plane.*/
if r\='' then say strip(r,'T') /*crop completely white rows. */
end
end
</lang>
</lang>
Output
Output
<pre style="height:50ex;overflow:scroll">
<pre style="height:50ex;overflow:scroll">
──────── Langton's ant walked 11565 steps. ────────
──────── Langton's ant walked 11759 steps. ────────


██
██
████
████
█ ██ █
█ ██ █
██ ████
████ ██
██
█ █ █ █
███ ██ ██ ██
██ █ ██
███ ██
█ ██
███ ██ ███ ███
██ █ ███
███ ██ ████
██ ███
███ ██ ██
██ ██ ██ █ ███
███ ██ ██ ██
██ ███
███ █ ██ ██ █ ████
███ ███ ██ ███
███ ██ ██ ██ ███ ██ █████
████ ██ █ █ ███
███ ██ ██ ████ ██ ██
██ ██ █ ███
███ ██ ████ ████ ███ ████
██ ██ ██ █ █ ███
███ ██ ██ ██ ██ █ ███
████ ██ ██ ███
███ ██ ██ ██ ████
█████ ██ ███ ██ ██ ██ ███
███ ██ ██ ██ ██ █
██ ██ ████ ██ ██ █ ███
███ ████████ ██ ████
████ ███ ████ ████ ██ █ █ █ ███
███ █ ██ ██ ██ ██ ██ █ █ ██ █ ██ ██
███ ██ ██ ██ ██ █ ███
███ █ █ █████ ██ ██ █ █ █ █
████ ██ ██ ██ █ █ ███
███ ████ ██ ████ ██ ████ ██
██ ██ ██ ██ █ ███
███ ████ █████ ██ ██████████ ██
████ ██ ████████ █ █ ███
███ █ ██ █ █ ██ █████ ██ ██ █
██ ██ ██ ██ ██ █ █ ██ ██ ██ ███
███ █ █ █████ █ █████ ██ ██
█ █ █ ██ ██ █ █████ ███
███ ██ ██████ ██ ██ ███ ███ ██ █
██ ████ ██ ████ ██ ██ █ ██ █ ███
███ ████ ██ ██ ███ ███ ██ ████
██ ██████████ ██ █████████ █ █ █ █ ███
███ █ ██ ████ ██ █████████ ██ ██
██ █ ██ █████ ██ ██ ███
███ █ ███ ███████████ ████ █ █
██ ██ ██████████ █ █ █ ███
███ ██ ███ ██ █ ██ ████ ████
██ ███ ███ ██ █ ██ ██████ █ ██ █ ███
███ ███ ██ ██ █ █ █ █
████ ██ █ █ ███ ███ ██ ██ ██ ██ █ █ ███
███ ██ █ ██ ██ █████ ████ ████ ██ █
██ ██ █████████ ██ ████ █ ██ ███
███ █ ██ █ █ ███ ███ ██ █ ██
███████████████ ██ █ █ █ ███ █
███ █ █ █ █ ████ ██ ██ ███
████ ████ ██ █ ██ ███ ██ █ ███
███ ██ ██ ██ ███ ██ ████
██ ██ █ ███ █ █ ███
███ █ █ ██ ███ ██ █ ███ ██ ██ █
██ ████ ████ █████ ██ ██ █ ██ █ █ ███
█ █ ██ ██ ██ ██ ██
██ ██ ███ ███ █ █ ██ █ ███
█ █ ██ ███ █ █ ████ █ ██
███ ██ ██ ████ █ █ █ █ █ ███
███ ██ █ █ ██ ██ ██ █████ ███ ██
████ ██ ███ ██ ██ ██ ███
███ ██ ████ ██ ██ ██████ ███
██ ██ ███ ██ █ ███ ██ █ █ ███
█████ ████ ███ █ █
██ ██ ████ ██ █ █
███ ██ ██ ███ █ █ ███ ███
██ ████ ███ ██ █ █ █
█ ███ ██ ████ ██ █ █ █ ██ ██
██ ███ ███████ ██ ██ █ █ █████
███ █ █ █ ██ ██ ███
███ █ ██████ ██ ██ ████ █ ██ ███
██ ██ █ █ ███
███ ████ █ █ █████
█ █ █ █ █ █
███ ███ █ █ ███ ████ ███
███ ██ ██
██ ██ ██ ████ ██ ███
████ ██
███ ██ ██ █ █ ███
██ ████████████ ██
███ ██ ██
█ █ █ █ █ █
█ ██ ██ ███
██ █ ████ █
██ ████████████ ██
</pre>
</pre>