Most efficient way to find next 13rd Friday using programming [duplicate]
Possible Duplicate:
Calculating future occurences of Friday the 13th
As i sip my beer and get bored, that question came into my mind. How could find the next 13rd Friday efficiently using popular programming languages like C, Java, C#, Python, Perl, PHP even Lisp, ALGOL etc. Which code does seem shortest and smarter?
many ways. Heres one. Note I didn't check if it parsed but the idea is right.
C#:
DateTime date = DateTime.Now; // as today is 13th. If system date changes then hardcode date.
while (date < <Some date in the future you want to report to>)
{
date = date.AddMonths(1);
if (date.DayOfWeek == DayOfWeek.Friday)
System.Console.PrintLine(date.ToString());
}
精彩评论