In Probability and Stats last semester, my professor assigned us the project of determining how many students there would need to be in a class in order to have a 50/50 chance of having a repeat birth date. It’s called the Birthday Problem or Birthday Paradox. He mentioned that it’s quite a popular problem in probability classes, and that we cannot look online for the answer.
He wanted us to use our intuition to form a method for finding the answer. Obviously, since I’m a CS major, I turned to the computer for my answer. I was taking Fortran that same semester, so it was the freshest language on my mind. Any programming language would probably do, but I chose this one. A lot of what I’ve seen on the web with this problem is written in C or C++, so I feel I have a slight advantage here. ;~] Upon compiling and running the program, I came to my answer in less than one second: 23.
~Jonathan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ! --------------------------------------------------------- ! Programmer: Jonathan Landrum ! Date: 20 September 2011 ! Class: MAT 353 ! --------------------------------------------------------- ! Program: birthdays.exe ! Purpose: Calculates the number of people you ! would need to question in order to have ! a 50% chance in getting two or more ! duplicate birth dates among the set. ! Assumptions: None. ! --------------------------------------------------------- PROGRAM BIRTHDAYS IMPLICIT NONE REAL :: probability = 0.0, compliment = 1.0, days = 365 INTEGER :: counter = 1 CHARACTER :: response WRITE (*,*) '******************************************' WRITE (*,*) '* *' WRITE (*,*) '* FORTRAN DUPLICATE BIRTHDATE CALCULATOR *' WRITE (*,*) '* *' WRITE (*,*) '******************************************' WRITE (*,*) WRITE (*,*) 'Calculates the number of people you would' WRITE (*,*) 'need to question in order to have a 50/50' WRITE (*,*) 'chance in having a duplicate birthdate.' WRITE (*,*) WRITE (*,*) 'This program takes no arguments from the' WRITE (*,*) 'user, except to continue after this line.' WRITE (*,*) WRITE (*,*) 'Would you like to continue? [Y/N]' WRITE (*,*) READ (*,*) response ! Any response beginning with the letter "y" will do. WHILE (response == 'y' .OR. response == 'Y') DO ! ------------------------------------------------- ! Main: ! This loop begins at 1 with the calculation and ! continues until probability is greater than 50%. ! ------------------------------------------------- WHILE (probability < 0.51) DO compliment = compliment * (days/365) probability = 1.0 - compliment WRITE (*,*) '| ', counter, ' | ', probability, ' |' counter = counter + 1 days = days - 1 END DO ! Main loop WRITE (*,*) WRITE (*,*) 'Would you like to continue? [Y/N]' WRITE (*,*) READ (*,*) response END DO ! Continue loop WRITE (*,*) WRITE (*,*) '\\//_ Live long and prosper.' END PROGRAM BIRTHDAYS |
Jonathan Landrum is a full-time husband and student, and a part-time research assistant and IT guy. He both works and studies at Mississippi College, where he is pursuing a Bachelor of Science in Computer Science. Continue reading…