What does the following batch program do? Try to take a guess before running it yourself:
@echo off
setlocal enabledelayedexpansion
set NUMROWS=10
set NUMCOLS=10
REM // These start at 10 so they're always 2 digits
set nFirstRow=10
set /a nLastRow=nFirstRow+NUMROWS-1
set nFirstCol=10
set /a nLastCol=nFirstCol+NUMCOLS-1
REM // This is a capital oh, not zero
set ON=O
set OFF=.
set Var1=0
set Var3=1
:Initialize
REM // CELLrrcc
for /L %%I in (%nFirstRow%,1,%nLastRow%) do (
for /L %%J in (%nFirstCol%,1,%nLastCol%) do (
set CELL%%I%%J=%OFF%
)
)
if %1[==[ goto :Pattern5
goto :Pattern%1
:Pattern1
REM // What is it?
set CELL1110=%ON%
set CELL1111=%ON%
set CELL1112=%ON%
goto :Render
:Pattern2
REM // What is it?
set CELL1011=%ON%
set CELL1112=%ON%
set CELL1210=%ON%
set CELL1211=%ON%
set CELL1212=%ON%
goto :Render
:Pattern3
REM // What is it?
set CELL1314=%ON%
set CELL1315=%ON%
set CELL1413=%ON%
set CELL1414=%ON%
set CELL1514=%ON%
goto :Render
:Pattern4
REM // What is it?
set CELL1314=%ON%
set CELL1413=%ON%
set CELL1414=%ON%
set CELL1415=%ON%
set CELL1514=%ON%
goto :Render
:Pattern5
for /L %%I in (%nFirstRow%,1,%nLastRow%) do (
for /L %%J in (%nFirstCol%,1,%nLastCol%) do (
if !RANDOM! GTR 16383 set CELL%%I%%J=%ON%
)
)
:Render
cls
set Var2=0
for /L %%I in (%nFirstRow%,1,%nLastRow%) do (
set ROW=
for /L %%J in (%nFirstCol%,1,%nLastCol%) do (
set ROW=!ROW!!CELL%%I%%J!
if !CELL%%I%%J!==%ON% set /a Var2=Var2+1
)
echo !ROW!
)
echo P:%Var2% / G:%Var1%
if %Var2%==0 goto :EOF
if %Var3%==0 goto :EOF
:Advance
set Var2=0
set nRow=%nFirstRow%
set Var3=0
:AdvanceRow
set nCol=%nFirstCol%
if %nRow%==%nFirstRow% (
set nPrevRow=%nLastRow%
set /a nNextRow=%nRow% + 1
) else if %nRow%==%nLastRow% (
set /a nPrevRow=%nRow% - 1
set nNextRow=%nFirstRow%
) else (
set /a nPrevRow=%nRow% - 1
set /a nNextRow=%nRow% + 1
)
:AdvanceCol
if %nCol%==%nFirstCol% (
set nPrevCol=%nLastCol%
set /a nNextCol=%nCol% + 1
) else if %nCol%==%nLastCol% (
set /a nPrevCol=%nCol% - 1
set nNextCol=%nFirstCol%
) else (
set /a nPrevCol=%nCol% - 1
set /a nNextCol=%nCol% + 1
)
set nSum=0
if !CELL%nPrevRow%%nPrevCol%!==%ON% set /a nSum=nSum+1
if !CELL%nPrevRow%%nCol%!==%ON% set /a nSum=nSum+1
if !CELL%nPrevRow%%nNextCol%!==%ON% set /a nSum=nSum+1
if !CELL%nRow%%nPrevCol%!==%ON% set /a nSum=nSum+1
if !CELL%nRow%%nNextCol%!==%ON% set /a nSum=nSum+1
if !CELL%nNextRow%%nPrevCol%!==%ON% set /a nSum=nSum+1
if !CELL%nNextRow%%nCol%!==%ON% set /a nSum=nSum+1
if !CELL%nNextRow%%nNextCol%!==%ON% set /a nSum=nSum+1
set NEWCELL%nRow%%nCol%=!CELL%nRow%%nCol%!
if %nSum% GTR 3 (
set NEWCELL%nRow%%nCol%=%OFF%
) else if %nSum%==3 (
set NEWCELL%nRow%%nCol%=%ON%
) else if %nSum% LSS 2 (
set NEWCELL%nRow%%nCol%=%OFF%
)
if not !NEWCELL%nRow%%nCol%!==!CELL%nRow%%nCol%! set /a Var3=Var3+1
set /a nCol=%nCol% + 1
if not %nCol% GTR %nLastCol% goto :AdvanceCol
set /a nRow=%nRow% + 1
if not %nRow% GTR %nLastRow% goto :AdvanceRow
for /L %%I in (%nFirstRow%,1,%nlastRow%) do (
for /L %%J in (%nFirstCol%,1,%nLastCol%) do (
set CELL%%I%%J=!NEWCELL%%I%%J!
)
)
set /a Var1=Var1 + 1
goto :Render
Twenty imaginary gold doubloons to the pirate that first guesses correctly. I think I might have created the worst-performing implementation of this particular algorithm.
Um... the game of life in a 10x10 grid?
ReplyDeleteAlso, by the way, when you begin writing a post on, say, November 10th, save it, then publish it on, say, December 7th, Blogger will use the date of first save for the publish date. If many other posts have been made since then, it will appear underneath them all, not at the top of the main page, as you may have intended.
ReplyDeleteHowever, if the Blog Owner happens to have all blog posts and comments e-mailed to him, he might immediately see the post, even though no one else does because it's buried, and correct the date for you, if he is kind.
This is, of course, just an FYI for a hypothetical scenario.
Thanks, I hadn't finished editing the post. I wish Blogger had a feature that would show you how your post was going to look before you posted it. You know, like maybe a "Preview" link while you were editing it. You know, sort of like the one that was already there, but, you know, WORKED.
ReplyDeleteDang! That tears it. I'm setting my RSS reader to update every 5 minutes. I really needed those doubloons.
ReplyDeleteBTW, I can't say enough of how un-freakin'-believable that is. I'm impressed beyond words. Or at least beyond words that can be used in civil society.
I assume you're talking about my 1-generation-per-second 10x10 batch file implementation, and not Golly's unbounded 2,000,000+ gen/sec epic number cruncher.
ReplyDelete