Day of the week: Difference between revisions
Content added Content deleted
m (Fixed tags) |
|||
Line 270: | Line 270: | ||
{{works with|Fortran|90 and later}} |
{{works with|Fortran|90 and later}} |
||
Based on Forth example |
Based on Forth example |
||
<lang fortran>PROGRAM YULETIDE |
|||
IMPLICIT NONE |
|||
INTEGER :: day, year |
|||
WRITE(*, "(A)", ADVANCE="NO") "25th of December is a Sunday in" |
|||
DO year = 2008, 2121 |
|||
day = Day_of_week(25, 12, year) |
|||
IF (day == 1) WRITE(*, "(I5)", ADVANCE="NO") year |
|||
END DO |
|||
CONTAINS |
|||
FUNCTION Day_of_week(d, m, y) |
|||
INTEGER :: Day_of_week, j, k |
|||
INTEGER, INTENT(IN) :: d, m, y |
|||
j = y / 100 |
|||
k = MOD(y, 100) |
|||
Day_of_week = MOD(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7) |
|||
END FUNCTION Day_of_week |
|||
END PROGRAM YULETIDE</lang> |
|||
Output |
Output |
||
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 |
25th of December is a Sunday in 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118 |
||
Line 313: | Line 313: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Using the time library: |
Using the time library: |
||
⚫ | |||
<pre> |
|||
⚫ | |||
import Data.Time.Calendar.WeekDate |
import Data.Time.Calendar.WeekDate |
||
Line 321: | Line 320: | ||
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday" |
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday" |
||
| year <- [2008..2121], isXmasSunday year] |
| year <- [2008..2121], isXmasSunday year]</lang> |
||
</pre> |
|||
Output: |
Output: |
||
<pre> |
<pre> |
||
Line 345: | Line 343: | ||
The built-in System.Time module overflows at the Unix epoch in 2038: |
The built-in System.Time module overflows at the Unix epoch in 2038: |
||
⚫ | |||
<pre> |
|||
⚫ | |||
isXmasSunday year = ctWDay cal == Sunday |
isXmasSunday year = ctWDay cal == Sunday |
||
Line 366: | Line 363: | ||
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday" |
main = mapM_ putStrLn ["25 December " ++ show year ++ " is Sunday" |
||
| year <- [2008..2121], isXmasSunday year] |
| year <- [2008..2121], isXmasSunday year]</lang> |
||
</pre> |
|||
Output on 32-bit machine: |
Output on 32-bit machine: |
||
<pre> |
<pre> |
||
Line 424: | Line 420: | ||
Consequently, it suffers from the same problem as C. |
Consequently, it suffers from the same problem as C. |
||
⚫ | |||
<pre> |
|||
⚫ | |||
IMPORT IO, Fmt, Date, Time; |
IMPORT IO, Fmt, Date, Time; |
||
Line 452: | Line 447: | ||
END; |
END; |
||
END; |
END; |
||
END Yule. |
END Yule.</lang> |
||
</pre> |
|||
Output: |
Output: |