Calculating future occurrences of Friday the 13th

前端 未结 7 1777
庸人自扰
庸人自扰 2020-12-15 12:48

I\'d like to be able to start with a year, and calculate occurrences of Friday the 13th. A brute force solution is easy and obvious. I have something slightly better, but

7条回答
  •  不知归路
    2020-12-15 13:27

    Since your brute force algorithm is apparently the intuitive day-by-day iteration option, perhaps you haven't considered the Doomsday Algorithm. It would allow you to simply check if that 13th is a Friday. As far as I know, it is the most efficient solution to the problem.

提交回复
热议问题