Which day of the week (Sunday, Monday, etc.) is the probability largest to fall on the 13th of a random month, in a random year?
Or is this probability the same for each day of the week?
I wrote a Visual Basic program that counts beginning with 2004. I used the correct definition of a leap year: a non-century year divisible by 4, or a century divisible by 400. I verified program results for 2004-2005.
For 2004-1000000, Friday is most likely -- Friday the 13th. There will be 1714060 Sundays, 1709071 Mondays, 1709070 Tuesdays, 1714060 Wednesdays, 1706574 Thursdays, 1716555 Fridays and 1706574 Saturdays that fall on the 13th of the month. (Of course, by 1000000 AD, only Alan Greenspan will still be around to verify this).
Imports System
Imports System.IO
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.Math
Module Module1
Sub Main()
Randomize()
Dim strgo As String
strgo = "y"
While strgo = "y"
mainline()
Console.WriteLine("Again ? (y/n)")
strgo = LCase(Console.ReadLine())
End While
End Sub
Sub mainline()
Dim inttargetyear As Integer
Dim intdays(7, 1) As Integer
Dim intsub As Integer
Dim intweekday As Integer = 0
Dim intweekday2 As Integer
Dim intweekday7 As Integer
Dim intmonth As Integer
Dim strday As String
Dim strleapyear As String
Dim strlastyear As String
inttargetyear = 0
While inttargetyear < 2004
Console.WriteLine("Enter ending year (>= 2004)")
inttargetyear = Int(Console.ReadLine())
End While
For index1 As Integer = 0 To 6
intdays(index1, 0) = 0
Next
intweekday = 0
For index0 As Integer = 2004 To inttargetyear
If index0 Mod 400 = 0 Then
strleapyear = "y"
ElseIf index0 Mod 100 = 0 And _
index0 Mod 400 <> 0 Then
strleapyear = "n"
ElseIf index0 Mod 4 = 0 Then
strleapyear = "y"
Else
strleapyear = "n"
End If
If index0 > 2004 Then
If (index0 - 1) Mod 400 = 0 Then
strlastyear = "y"
ElseIf (index0 - 1) Mod 100 = 0 And _
(index0 - 1) Mod 400 <> 0 Then
strlastyear = "n"
ElseIf (index0 - 1) Mod 4 = 0 Then
strlastyear = "y"
Else
strlastyear = "n"
End If
End If
If index0 = 2004 Then
intweekday7 = 4
ElseIf strlastyear = "y" Then
intweekday7 += 2
Else
intweekday7 += 1
End If
intweekday7 = intweekday7 Mod 7
intweekday = 0
intweekday2 = intweekday7 - 1
intmonth = 1
If strleapyear = "n" Then
For index1 As Integer = 1 To 365
intweekday += 1
intweekday2 += 1
If intweekday = 29 Then
If intmonth = 2 Then
intmonth += 1
intweekday = 1
End If
ElseIf intweekday = 31 Then
If intmonth = 4 Or intmonth = 6 _
Or intmonth = 9 Or _
intmonth = 11 Then
intmonth += 1
intweekday = 1
End If
ElseIf intweekday = 32 Then
If intmonth <> 2 And intmonth <> 4 And _
intmonth <> 6 And intmonth <> 9 And intmonth <> 11 Then
intmonth += 1
intweekday = 1
End If
End If
If intweekday = 13 Then
intdays(intweekday2 Mod 7, 0) += 1
End If
Next
Else
For index1 As Integer = 1 To 366
intweekday += 1
intweekday2 += 1
If intweekday = 30 Then
If intmonth = 2 Then
intmonth += 1
intweekday = 1
End If
ElseIf intweekday = 31 Then
If intmonth = 4 Or intmonth = 6 _
Or intmonth = 9 Or _
intmonth = 11 Then
intmonth += 1
intweekday = 1
End If
ElseIf intweekday = 32 Then
If intmonth <> 2 And intmonth <> 4 And _
intmonth <> 6 And intmonth <> 9 And intmonth <> 11 Then
intmonth += 1
intweekday = 1
End If
End If
If intweekday = 13 Then
intdays(intweekday2 Mod 7, 0) += 1
End If
Next
End If
Next
For index1 As Integer = 0 To 6
getday(index1, strday)
Console.WriteLine(strday & ": " & _
Str(intdays(index1, 0)))
Next
End Sub
Sub getday(ByRef index1, ByRef strday)
Select Case index1
Case 0
strday = "Sunday"
Case 1
strday = "Monday"
Case 2
strday = "Tuesday"
Case 3
strday = "Wednesday"
Case 4
strday = "Thursday"
Case 5
strday = "Friday"
Case 6
strday = "Saturday"
End Select
End Sub
End Module
Edited on August 13, 2004, 2:08 pm
|
Posted by Penny
on 2004-08-13 13:17:38 |