Skip to content

Instantly share code, notes, and snippets.

@bobjansen
Created December 16, 2010 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobjansen/743874 to your computer and use it in GitHub Desktop.
Save bobjansen/743874 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
bool checkAddition(int y, int m, int d);
bool checkMultiply(int y, int m, int d);
bool checkDivision(int y, int m, int d);
bool checkSubstraction(int y, int m, int d);
bool checkAddition(int y, int m, int d) {
return y == m + d;
}
bool checkSubstraction(int y, int m, int d) {
return y == m - d;
}
bool checkMultiply(int y, int m, int d) {
return y == m * d;
}
bool checkDivision(int y, int m, int d) {
return static_cast<float>(y) == static_cast<float>(d) / static_cast<float>(m);
}
int main() {
int special = 0;
int extra = 0;
int counter = 0;
int addCounter = 0;
int subCounter = 0;
int mulCounter = 0;
int divCounter = 0;
int months[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
for (int y=0; y<100; y++) {
if (y%400==0 || (y%100 != 0 && y%4 == 0)) {
months[1] = 29;
} else {
months[1] = 28;
}
for (int m=1; m<=12; m++) {
for (int d=1; d<=months[m-1]; d++) {
extra = 0;
if (checkAddition(y, m, d)) {
cout << "Add: " << d << "-" << m << "-" << y << " ";
addCounter++;
extra++;
}
if (checkSubstraction(y, m, d)) {
cout << "Sub: " << d << "-" << m << "-" << y << " ";
subCounter++;
extra++;
}
if (checkMultiply(y, m, d)) {
cout << "Mul: " << d << "-" << m << "-" << y << " ";
mulCounter++;
extra++;
}
if (checkDivision(y, m, d)) {
cout << "Div: " << d << "-" << m << "-" << y;
divCounter++;
extra++;
}
if (extra > 1)
special++;
if (extra > 0) {
counter++;
cout << endl;
}
}
}
}
cout << "Adds: " << addCounter << endl;
cout << "Subs: " << subCounter << endl;
cout << "Mults: " << mulCounter << endl;
cout << "Divs: " << divCounter << endl;
cout << "Number of magic dates: " << counter << endl;
if (special > 0)
cout << "Some dates are extra special!" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment