Jump to content

Day of the week: Difference between revisions

→‎{{header|Batch File}}: shortened code (this section is among my first contributions here huhuhu)
(Added Algol W)
(→‎{{header|Batch File}}: shortened code (this section is among my first contributions here huhuhu))
Line 754:
 
=={{header|Batch File}}==
<lang dos>:: Day of the Week task from Rosetta Code Simi
<lang dos>
:: Day of the Week task from Rosetta Code Simi
 
:: 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
::Setrem set month code for December
 
::Set month code for December
set mon=33
::Setrem set day number
 
::Set day number
set day=25
 
for /L %%wy in (2008,1,2121) do (
setlocal enabledelayedexpansion
call :check_day %%w
set /a "a=%yr%y/100"
)
set /a "b=%yr%y-(%a%*100)"
pause>nul
set /a "weekday=(%day%+%mon%+%b%+(%b%/4)+(%a%/4)+(5*%a%))%%7"
exit /b
echo if "!weekday!"=="1" echo(Dec 25, %yr%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>nul
goto :EOF
exit /b 0</lang>
{{out}}
<pre>Dec 25, 2011 is a Sunday.
<pre>
Dec 25, 2011 is a Sunday.
Dec 25, 2016 is a Sunday.
Dec 25, 2022 is a Sunday.
Line 806 ⟶ 793:
Dec 25, 2112 is a Sunday.
Dec 25, 2118 is a Sunday.
Press any key to continue . . .</pre>
</pre>
 
=={{header|BBC BASIC}}==
535

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.