Last active
December 27, 2015 12:19
-
-
Save ardeshir/7325376 to your computer and use it in GitHub Desktop.
Calculate the possible match of someone's birthday with yours
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
#include <math.h> | |
#include <stdio.h> | |
typedef struct { | |
double one_match; | |
double none_match; | |
} bday_struct; | |
int upto = 40; | |
void calculate_days(bday_struct days[]); | |
void print_days(bday_struct days[]); | |
int main(int argc, char const *argv[]) { | |
bday_struct days[upto+1]; | |
calculate_days(days); | |
print_days(days); | |
return 0; | |
} | |
void calculate_days(bday_struct days[]) { | |
int ct; | |
days[1].none_match = 1; | |
for(ct=2; ct<=upto; ct ++) { | |
days[ct].one_match = 1 - pow(364/365., ct - 1); | |
days[ct].none_match = days[ct-1].none_match * (1 - (ct - 1)/365.); | |
} | |
} | |
void print_days(bday_struct days[]) { | |
int ct; | |
printf("People\tMatches me\t Any match\n"); | |
for(ct = 2; ct<=upto; ct ++) { | |
printf("%i\t%.3f\t\t%.3f\n", ct, days[ct].one_match, 1 - days[ct].none_match); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment