Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many Friday 13th in a year?

Status
Not open for further replies.

GwydionM

Programmer
Oct 4, 2002
742
GB
Can anyone figure the average? The maximum? Could we have a year without any?

------------------------------
An old man [tiger] who lives in the UK
 
[white]
There are only 14 year-calendars in a perpetual calendar system:[ul][li]Seven calendars have January 1 on each of a different weekday,[/li][li]Seven have January 1 on each of a different weekday and with a leap day in February[/li][/ul]

Using this little knockoff PHP script:

Code:
<?php

$thirteenths      = array (13, 44, 72, 103, 133, 164, 194, 225, 256, 286, 317, 347);
$leap_thirteenths = array (13, 44, 73, 104, 134, 165, 195, 226, 257, 287, 318, 348);
$day_names = array ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');

for ($week_start_shift = 0; $week_start_shift <= 6; $week_start_shift++)
{
	print $day_names[$week_start_shift] . ':';

	$leap_days = 0;
	foreach ($thirteenths as $thirteen)
	{
		if (($thirteen  + $week_start_shift) % 7 == 6)
		{
			$leap_days++;
		}
	}
	print $leap_days . ':';

	$leap_days = 0;
	foreach ($leap_thirteenths as $thirteen)
	{
		if (($thirteen  + $week_start_shift) % 7 == 6)
		{
			$leap_days++;
		}
	}
	print $leap_days . "\r\n";
}
?>

I get the output:

Sun:2:3
Mon:2:2
Tue:2:1
Wed:1:2
Thu:3:2
Fri:1:1
Sat:1:1

It looks like:[ul][li]the minimum number of Friday the 13ths is 1 (in non-leap years in which Jan 1 is a Wednesday, Friday, or Saturday or leap years in which Jan 1 is a Tuesday, Friday, or Saturday),[/li][li]the max is 3 (in non-leap years in which Jan 1 is a Thursday or leap years where Jan 1 is a Sunday), and[/li][li]the average is ~ 1.7 Friday the 13ths/year.[/li][/ul][/white]



Want the best answers? Ask the best questions! TANSTAAFL!
 
This is a variation on thread1551-1208763. In fact should be even easier to do.

If I find time I will modify the code I posted in that thread to solve this one also, and do it without loops, without branching, without tables, without user defined functions, etc in any given year. Might even be possible to solve it without all all the above over multiple years. Will have to think about that one.

Gut feeling is that there should be at least one Friday the 13th in every year, but no more than 3. Will confirm or disprove this feeling when/if I get around to refining my code.




mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Oops, I guess I should have read the previous post first.

He confirmed my gut feelings before I even posted my last reply. LOL


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
I always like it when my birthday falls on Friday the 13th; almost as much as when it falls on Columbus Day!





Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top