Long year: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|Perl 6}}: remove dupe)
m (→‎{{header|Perl 6}}: Throw another century in there because, why not?)
Line 10: Line 10:


# Testing
# Testing
say "Long years in the 20th century:\n", (1900..2000).grep: *.&is-long;
say "Long years in the 20th century:\n", (1900..^2000).grep: *.&is-long;
say "\nLong years in the 21st century:\n", (2000..2100).grep: *.&is-long;</lang>
say "\nLong years in the 21st century:\n", (2000..^2100).grep: *.&is-long;
say "\nLong years in the 22nd century:\n", (2100..^2200).grep: *.&is-long;</lang>
{{out}}
{{out}}
<pre>Long years in the 20th century:
<pre>Long years in the 20th century:
Line 18: Line 19:
Long years in the 21st century:
Long years in the 21st century:
(2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099)
(2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099)

</pre>
Long years in the 22nd century:
(2105 2111 2116 2122 2128 2133 2139 2144 2150 2156 2161 2167 2172 2178 2184 2189 2195)</pre>


=={{header|Ruby}}==
=={{header|Ruby}}==

Revision as of 23:12, 9 January 2020

Long year is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Most years have 52 weeks, some have 53, according to ISO8601. Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.


Perl 6

Works with: Rakudo version 2019.11

December 28 is always in the last week of the year. (By ISO8601) <lang perl6>sub is-long ($year) { Date.new("$year-12-28").week[1] == 53 }

  1. Testing

say "Long years in the 20th century:\n", (1900..^2000).grep: *.&is-long; say "\nLong years in the 21st century:\n", (2000..^2100).grep: *.&is-long; say "\nLong years in the 22nd century:\n", (2100..^2200).grep: *.&is-long;</lang>

Output:
Long years in the 20th century:
(1903 1908 1914 1920 1925 1931 1936 1942 1948 1953 1959 1964 1970 1976 1981 1987 1992 1998)

Long years in the 21st century:
(2004 2009 2015 2020 2026 2032 2037 2043 2048 2054 2060 2065 2071 2076 2082 2088 2093 2099)

Long years in the 22nd century:
(2105 2111 2116 2122 2128 2133 2139 2144 2150 2156 2161 2167 2172 2178 2184 2189 2195)

Ruby

<lang ruby> require 'date'

def long_year?(year = Date.today.year)

 Date.new(year, 12, 28).cweek == 53

end

(2020..2030).each{|year| puts "#{year} is long? #{ long_year?(year) }." } </lang>

Output:
2020 is long? true.
2021 is long? false.
2022 is long? false.
2023 is long? false.
2024 is long? false.
2025 is long? false.
2026 is long? true.
2027 is long? false.
2028 is long? false.
2029 is long? false.
2030 is long? false.