Anonymous user
Langton's ant: Difference between revisions
→{{header|REXX}}: added/changed comments and whitespace, add a more idiomatic direction handler, added support for the character used for the path.
m (→{{header|Sidef}}: minor code simplifications) |
(→{{header|REXX}}: added/changed comments and whitespace, add a more idiomatic direction handler, added support for the character used for the path.) |
||
Line 3,801:
This REXX program automatically justifies (or ''crops'') the '''left''', '''right''', '''top''' and '''bottom''' of the ant's walk field on the screen.
<br>Or in other words, this REXX program only shows the pertinent part of the ant's walk-field.
<lang rexx>/*REXX program implements Langton's ant walk and displays the
parse arg dir char .
if char=='' then
@.=0 /*define stem array (all white).*/
x=(
if dir=='' then dir=random(1,4) /*ant is facing random direction,*/
$.=1; $.0=4; $.2=2; $.3=3; $.4=4 /*1≡north 2≡east 3≡south 4≡west*/
/*1=north 2=east 3=south 4=west*/▼
/*───────────────────────────────────────────ant walks hither & thither.*/
do steps=1 until x<
black=@.x.y; @.x.y= \
dir=$.dir
when
▲ end /*select*/
▲ end /*steps*/
/*───────────────────────────────────────────the ant is finished walking*/
say center(" Langton's ant walked" steps 'steps. ', 79, "─"); say
/*
do minx =
do y=
if @.minx.y then leave minx
end /*y*/
end /*minx*/
do y=
_=strip(translate(_,char,10), 'T') /*color the cells: black | white.*/
▲ end /*x*/
if _\==
'''output'''
<pre style="height:60ex">
|