Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Five-weekends/D/five-weekends-1.d
Normal file
31
Task/Five-weekends/D/five-weekends-1.d
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import std.stdio, std.datetime, std.algorithm, std.range;
|
||||
|
||||
Date[] m5w(in Date start, in Date end) pure /*nothrow*/ {
|
||||
typeof(return) res;
|
||||
// adjust to 1st day
|
||||
for (Date when = Date(start.year, start.month, 1);
|
||||
when < end;
|
||||
when.add!"months"(1))
|
||||
// Such month must have 3+4*7 days and start at friday
|
||||
// for 5 FULL weekends.
|
||||
if (when.daysInMonth == 31 &&
|
||||
when.dayOfWeek == DayOfWeek.fri)
|
||||
res ~= when;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool noM5wByYear(in int year) pure {
|
||||
return m5w(Date(year, 1, 1), Date(year, 12, 31)).empty;
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable m = m5w(Date(1900, 1, 1), Date(2100, 12, 31));
|
||||
writeln("There are ", m.length,
|
||||
" months of which the first and last five are:");
|
||||
foreach (d; m[0 .. 5] ~ m[$ - 5 .. $])
|
||||
writeln(d.toSimpleString()[0 .. $ - 3]);
|
||||
|
||||
immutable n = iota(1900, 2101).filter!noM5wByYear().walkLength();
|
||||
writefln("\nThere are %d years in the range that do not have " ~
|
||||
"months with five weekends.", n);
|
||||
}
|
||||
35
Task/Five-weekends/D/five-weekends-2.d
Normal file
35
Task/Five-weekends/D/five-weekends-2.d
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
void main() {
|
||||
import std.stdio, std.datetime, std.traits;
|
||||
|
||||
enum first_year = 1900;
|
||||
enum last_year = 2100;
|
||||
|
||||
uint totalNo5Weekends;
|
||||
immutable(Date)[] fiveWeekendMonths;
|
||||
foreach (immutable year; first_year .. last_year + 1) {
|
||||
bool has5Weekends = false;
|
||||
|
||||
foreach (immutable month; EnumMembers!Month) {
|
||||
immutable firstDay = Date(year, month, 1);
|
||||
if (firstDay.daysInMonth == 31 &&
|
||||
firstDay.dayOfWeek == DayOfWeek.fri) {
|
||||
has5Weekends = true;
|
||||
fiveWeekendMonths ~= firstDay;
|
||||
}
|
||||
}
|
||||
|
||||
if (!has5Weekends)
|
||||
totalNo5Weekends++;
|
||||
}
|
||||
|
||||
writefln("Total 5-weekend months between %d and %d: %d",
|
||||
first_year, last_year, fiveWeekendMonths.length);
|
||||
foreach (immutable date; fiveWeekendMonths[0 .. 5])
|
||||
writeln(date.month, ' ', date.year);
|
||||
"...".writeln;
|
||||
foreach (immutable date; fiveWeekendMonths[$ - 5 .. $])
|
||||
writeln(date.month, ' ', date.year);
|
||||
|
||||
writeln("\nTotal number of years with no 5-weekend months: ",
|
||||
totalNo5Weekends);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue