0

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?

Community
  • 1
  • 1
Erhan Bagdemir
  • 5,231
  • 6
  • 34
  • 40
  • Polling type questions aren't really considered welcome here on SO any more. If you have a question with a definitive, single, answer, go ahead. If you have a question with an unknown amout of answers, not so much. Voting to close. – Lasse V. Karlsen May 13 '11 at 21:53
  • http://stackoverflow.com/questions/546505/calculating-future-occurences-of-friday-the-13th . And perhaps this fits better at Code Golf? – Bart May 13 '11 at 21:55
  • 1
    Also note that "getting boring" is never a good quality. "getting bored" is better :) – Lasse V. Karlsen May 13 '11 at 21:57
  • i just wanted to get the shortest or smartest answer coded in any language. i have a Java version. next, i want to start with learning a new PL. I think that i could get interesting answers from SO community and help me to motivate. – Erhan Bagdemir May 13 '11 at 21:58
  • If you wanted shortest as in "fewest glyphs used to express the source code", that's not really that great a goal. I could probably beat everyone here by that metric using APL, but that doesn't mean APL is the best language. – T.E.D. May 13 '11 at 22:17
  • APL ? i think that i haven't heard something like that so far. Thank you very much for your suggestion. I made a little research and i see that it is influenced by mat. notations. However, your answer was one of what i expected actually. I'm trying to write the algorithm in Lisp and will match with Java- version and try to get it smarter. I would like to compare my version with community's which're programmed with commonly used programming languages, like C#, Python or maybe Objective C. I tend to learn Python next. I think that it would be a good choice for my target context. – Erhan Bagdemir May 13 '11 at 22:36

1 Answers1

1

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());
}
Vinnyq12
  • 1,519
  • 9
  • 9