Five weekends: Difference between revisions

→‎{{header|Perl 6}}: Added Perl 6 solution
(→‎{{header|Tcl}}: extra credit)
(→‎{{header|Perl 6}}: Added Perl 6 solution)
Line 165:
2091
2096</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2010-10}}
<lang perl6># A month has 5 weekends iff it has 31 days and starts on Friday.
# Note: [@happy.end X- ^5].reverse is a workaround; Rakudo does not yet allow [*-5..*].
 
my @years = 1900 .. 2100;
my @ym = @years X < 01 03 05 07 08 10 12 >; # Months with 31 days
 
my @happy = @ym.map({ Date.new: "$^a-$^b-01" }).grep: { .day-of-week == 5 };
 
say 'Happy month count: ', +@happy;
say 'First happy months: '~ @happy[^5];
say 'Last happy months: '~ @happy[@happy.end X- ^5].reverse;
say 'Dreary years count: ', @years - @happy».year.uniq;
</lang>
Output:
<pre>
Happy month count: 201
First happy months: 1901-03-01 1902-08-01 1903-05-01 1904-01-01 1904-07-01
Last happy months: 2097-03-01 2098-08-01 2099-05-01 2100-01-01 2100-10-01
Dreary years count: 29
</pre>
 
=={{header|Python}}==
256

edits