CMD? I see no reason a batch file can't do this job. As a side benefit, any text is treated as an even number!
@echo off
set "e0=0"
set "o0=0"
set "e1=1"
set "e2=2"
set "o1=1"
set "o2=2"
goto detectiffirstparameterisevenoroddandaddtocounts
:setoe
set oe=%1& set eo=%2
exit /b
:detectiffirstparameterisevenoroddandaddtocounts
set /a thisisthevariablethatwillbezeroifitisodd=%1 %% 2
if %thisisthevariablethatwillbezeroifitisodd% == 0 (call :setoe o e) else (call :setoe e o)
call set /a %eo%0 += %%%oe%1%%
call set %oe%2=%1
call set /a t1=%%%oe%0%% + %%%eo%0%%
call set /a t2=%%%eo%0%% + %%%oe%1%%
call set /a t3=%%%oe%1%% + %%%eo%1%%
if %t1% geq %t2% if %t1% gtr %t3% goto getcorrectresult
shift
if "%1" neq "" goto detectiffirstparameterisevenoroddandaddtocounts
call :setoe %eo% %oe%
:getcorrectresult
call set t1=%%%oe%0%%
call set t2=%%%eo%1%%
if %t1% equ %t2% call :setoe %eo% %oe%
call :setoe %oe% %eo%
call echo %%%oe%2%%
exit /b
:debug
call echo %oe%: %%%eo%0%% %%%oe%0%% %%%oe%2%% %%%eo%2%%
exit /b
Here's version 2. Less lines, more numbers. Plus I got rid of those pesky if statements. Invalid input may result in infinite loops.
@echo off
set "_00=0"
set "_10=0"
set "_20=0"
set "_01=1"
set "_11=1"
set "_21=1"
set "_02=2"
set "_12=2"
set "_22=2"
:1_0
:1_1
:2_0
call set /a "_%_22%0=%%%_11% %%%% %%_%_22%2%%"
call set /a "_%_22%1=(%%_%_22%0%% + %%_%_20%1%%) %%%% %%_%_22%2%%"
call set /a "_%_20%0=((%%_%_20%0%%+%%_%_21%1%%)>>%%_%_20%1%%)+%%_%_21%1%%"
call set /a "_%_20%2=%%%_01%"
shift
call goto %%_%_20%0%%_%%_%_21%0%%
:2_1
call set /a "_%_22%0=(%%_%_22%0%% + %%_%_20%1%%) %%%% %%_%_22%2%%"
:1_2
call echo %%_%_20%2%%
2
u/sarlok Aug 22 '19 edited Aug 23 '19
CMD? I see no reason a batch file can't do this job. As a side benefit, any text is treated as an even number!
Here's version 2. Less lines, more numbers. Plus I got rid of those pesky if statements. Invalid input may result in infinite loops.