Five weekends: Difference between revisions

Ada solution added
(Ada solution added)
Line 14:
 
Count and/or show all of the years which do not have at least one five-weekend month (there should be 29).
=={{header|Ada}}==
<lang Ada>
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar.Formatting; use Ada.Calendar;
 
use Ada.Calendar.Formatting;
 
procedure Five_Weekends is
Months : Natural := 0;
begin
for Year in Year_Number range 1901..2100 loop
for Month in Month_Number range 1..12 loop
begin
if Day_Of_Week (Formatting.Time_Of (Year, Month, 31)) = Sunday then
Put_Line (Year_Number'Image (Year) & Month_Number'Image (Month));
Months := Months + 1;
end if;
exception
when Time_Error =>
null;
end;
end loop;
end loop;
Put_Line ("Number of months:" & Integer'Image (Months));
end Five_Weekends;
</lang>
Sample output:
<pre style="height:30ex;overflow:scroll">
1901 3
1902 8
1903 5
1904 1
1904 7
1905 12
1907 3
1908 5
1909 1
1909 10
1910 7
1911 12
1912 3
1913 8
1914 5
1915 1
1915 10
1916 12
1918 3
1919 8
1920 10
1921 7
1922 12
1924 8
1925 5
1926 1
1926 10
1927 7
1929 3
1930 8
1931 5
1932 1
1932 7
1933 12
1935 3
1936 5
1937 1
1937 10
1938 7
1939 12
1940 3
1941 8
1942 5
1943 1
1943 10
1944 12
1946 3
1947 8
1948 10
1949 7
1950 12
1952 8
1953 5
1954 1
1954 10
1955 7
1957 3
1958 8
1959 5
1960 1
1960 7
1961 12
1963 3
1964 5
1965 1
1965 10
1966 7
1967 12
1968 3
1969 8
1970 5
1971 1
1971 10
1972 12
1974 3
1975 8
1976 10
1977 7
1978 12
1980 8
1981 5
1982 1
1982 10
1983 7
1985 3
1986 8
1987 5
1988 1
1988 7
1989 12
1991 3
1992 5
1993 1
1993 10
1994 7
1995 12
1996 3
1997 8
1998 5
1999 1
1999 10
2000 12
2002 3
2003 8
2004 10
2005 7
2006 12
2008 8
2009 5
2010 1
2010 10
2011 7
2013 3
2014 8
2015 5
2016 1
2016 7
2017 12
2019 3
2020 5
2021 1
2021 10
2022 7
2023 12
2024 3
2025 8
2026 5
2027 1
2027 10
2028 12
2030 3
2031 8
2032 10
2033 7
2034 12
2036 8
2037 5
2038 1
2038 10
2039 7
2041 3
2042 8
2043 5
2044 1
2044 7
2045 12
2047 3
2048 5
2049 1
2049 10
2050 7
2051 12
2052 3
2053 8
2054 5
2055 1
2055 10
2056 12
2058 3
2059 8
2060 10
2061 7
2062 12
2064 8
2065 5
2066 1
2066 10
2067 7
2069 3
2070 8
2071 5
2072 1
2072 7
2073 12
2075 3
2076 5
2077 1
2077 10
2078 7
2079 12
2080 3
2081 8
2082 5
2083 1
2083 10
2084 12
2086 3
2087 8
2088 10
2089 7
2090 12
2092 8
2093 5
2094 1
2094 10
2095 7
2097 3
2098 8
2099 5
2100 1
2100 10
Number of months: 201
</pre>
=={{header|D}}==
<lang d>import std.gregorian ; // this module currently work in progress
Line 49 ⟶ 280:
 
output match [[#Python|python]] one.
 
=={{header|GAP}}==
<lang gap># return a list of two lists :