Day of the week: Difference between revisions

Content added Content deleted
(Added Algol W)
(→‎{{header|Batch File}}: shortened code (this section is among my first contributions here huhuhu))
Line 754: Line 754:


=={{header|Batch File}}==
=={{header|Batch File}}==
<lang dos>:: Day of the Week task from Rosetta Code
<lang dos>
:: Day of the Week task from Rosetta Code Simi

:: Batch File Implementation
:: Batch File Implementation
:: Question: In what years between 2008 and 2121 will the 25th of December be a Sunday?
::
:: Method: Zeller's Rule
:: In what years between 2008 and 2121 will the 25th of December be a Sunday?
::
:: This implementation uses Zeller's Rule...


@echo off
@echo off
rem set month code for December

::Set month code for December
set mon=33
set mon=33
rem set day number

::Set day number
set day=25
set day=25


for /L %%w in (2008,1,2121) do (
for /L %%y in (2008,1,2121) do (
setlocal enabledelayedexpansion
call :check_day %%w
set /a "a=%%y/100"
)
set /a "b=%%y-(a*100)"
pause>nul
set /a "weekday=(day+mon+b+(b/4)+(a/4)+(5*a))%%7"
exit /b
if "!weekday!"=="1" echo(Dec 25, %%y is a Sunday.

endlocal
:check_day
set yr=%1
set /a a=%yr%/100
set /a b=%yr%-(%a%*100)
set /a weekday=(%day%+%mon%+%b%+(%b%/4)+(%a%/4)+(5*%a%))%%7
if %weekday%==1 (
echo Dec 25, %yr% is a Sunday.
)
)
pause
goto :EOF
</lang>
exit /b 0</lang>
{{out}}
{{out}}
<pre>Dec 25, 2011 is a Sunday.
<pre>
Dec 25, 2011 is a Sunday.
Dec 25, 2016 is a Sunday.
Dec 25, 2016 is a Sunday.
Dec 25, 2022 is a Sunday.
Dec 25, 2022 is a Sunday.
Line 806: Line 793:
Dec 25, 2112 is a Sunday.
Dec 25, 2112 is a Sunday.
Dec 25, 2118 is a Sunday.
Dec 25, 2118 is a Sunday.
Press any key to continue . . .</pre>
</pre>


=={{header|BBC BASIC}}==
=={{header|BBC BASIC}}==