ラングトンのアリの描画
Posted feedbacks - Batchfile
バッチで。
e.g.
C:\>#276.bat 10
|
** |
* * |
* * |
* * |
**** |
|
|
|
|
X = 7, Y = 5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | @echo off
setlocal enabledelayedexpansion
set s=
set t=
set x=0
set y=0
set dx=-1
set dy=0
if "%~1" == "" (echo usage: %~n0 SIZE >&2 & exit /b 1)
set /a x=%~1/2,y=%~1/2
for /l %%j in (1,1,%~1) do (
for /l %%i in (1,1,%~1) do set c[%%i][%%j]=0
)
:_
if !x! lss 1 goto BREAK
if !x! gtr %~1 goto BREAK
if !y! lss 1 goto BREAK
if !y! gtr %~1 goto BREAK
if !c[%x%][%y%]! equ 0 (
set c[%x%][%y%]=1
set t=%dx%
set dx=%dy%
set /a dy=-!t!
) else (
set c[%x%][%y%]=0
set t=%dx%
set /a dx=-!dy!
set dy=!t!
)
set /a x+=%dx%,y+=%dy%
cls
for /l %%j in (1,1,%~1) do (
set s=
for /l %%i in (1,1,%~1) do (
if !c[%%i][%%j]! equ 0 (
set s=!s!
) else (
set s=!s!*
)
)
echo ^ !s!^|
)
echo X = %x%, Y = %y%
ping -n 2 127.0.0.1 > NUL
goto _
:BREAK
endlocal & echo DEAD END ...
|



Songmu #9331() [ JavaScript ] Rating8/10=0.80
- 黒いマスにアリがいた場合、90°右に方向転換し、そのマスの色を反転させ、1マス前進する。
- 白いマスにアリがいた場合、90°左に方向転換し、そのマスの色を反転させ、1マス前進する。
詳しくはWikipedia等で調べるか、参考ページに拙作のデモがありますのでご覧下さい。
see: JavaScriptでラングトンの蟻
Rating8/10=0.80-0+
[ reply ]