Five weekends: Difference between revisions

(→‎{{header|J}}: format inside verb)
(→‎{{header|D}}: added D)
Line 6:
# Show the ''number'' of months with this property.
# Show at least the first and last five dates, in order.
 
=={{header|D}}==
<lang d>import std.stdio ;
import std.gregorian ; // this module currently work in progress
 
Date[] m5w(Date start = Date(1900,1,1), Date end = Date(2100,12,31) ) {
Date[] res ;
for(Date when = Date(start.year, start.month, 1) ; // adjust to 1st day
when < end ;
when = Date(when.year, 1 + when.month, 1)) {
if(when.endOfMonthDay == 31) // Such month must has 3 + 4*7
if(when.dayOfWeek == 5 ) // days and start at friday
res ~= when ; // for 5 FULL weekends.
}
return res ;
}
 
void main() {
 
auto m = m5w() ; // use default input
writefln("There are %d months of which the first and last five are:",
m.length) ;
foreach(d;m[0..5]~m[$-5..$])
writefln("%s", d.toSimpleString[0..$-2]) ;
}</lang>
 
=={{header|J}}==
Anonymous user