Created
February 2, 2015 20:04
-
-
Save esnya/bc2d74c1e5ac8bd84168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto daysPerYaer(int year) { | |
if (year % 4 == 0 && !(year % 100 == 0 && year % 400 != 0)) { | |
return 366; | |
} else { | |
return 365; | |
} | |
} | |
unittest { | |
import std.algorithm; | |
import std.range; | |
assert(iota(2000, 2400).map!daysPerYaer().map!`a - 365`().sum() == 97); | |
static assert(iota(2000, 2400).map!daysPerYaer().map!`a - 365`().sum() == 97); | |
} | |
enum Day { | |
Saturday = 0, | |
Sunday, | |
Mondey, | |
Tuesday, | |
Wednesday, | |
Thursday, | |
Friday, | |
} | |
auto zeller(int y, int m, int d) { | |
if (m <= 2) { | |
m += 12; | |
y -= 1; | |
} | |
auto C = y / 100; | |
auto Y = y % 100; | |
auto Gamma = 5 * C + C / 4; | |
return cast(Day)(5 * C + Y + Y / 4 + C / 4 + 26 * (m + 1) / 10 + d) % 7; | |
} | |
unittest { | |
assert(zeller(2015, 2, 1) == Day.Sunday); | |
assert(zeller(2009, 2, 1) == Day.Sunday); | |
} | |
unittest { | |
import std.algorithm; | |
import std.range; | |
import std.typecons; | |
auto years = iota(1583, 2016).filter!(a => daysPerYaer(a) == 365)().filter!(a => zeller(a, 2, 1) == Day.Sunday)().array; | |
std.stdio.writeln(years); | |
std.stdio.writeln(years.length); | |
std.stdio.writeln(cast(real)(2016 - 1583) / years.length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment