TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Mental math - Find the day of the week a given date falls on

2 点作者 exupero超过 11 年前

1 comment

ColinWright超过 11 年前
There are many ways to do this, and the one given is one I really dislike. A lot.<p>Here&#x27;s the one I use.<p><pre><code> Each year has a magic number. For 2013 it&#x27;s 1. You can compute the magic number for the year. Subtract 1900 (or 2012). Divide by four, round down, and add it on. The magic number is (Y + Y&#x2F;4) % 7 Each year has a magic number: 1 4 4 (so January is 1) 0 2 5 0 3 6 (so August is 3) 1 4 6 (so November is 4) You can compute these, but I don&#x27;t recommend it. Add these two magic numbers, the day of the month, and compute the remainder mod 7. Then Sunday = 1 Wednesday = 4 etc. </code></pre> So Dec 25th, 2013 is given by (1 + 6 + 25) % 7 = Wednesday.<p>An adjust is required for dates in January or February in leap years.<p>Conway&#x27;s &quot;Doomsday Algorithm&quot;[0][1] is an alternative, and while Art Benjamin uses the same technique I do, he teaches a variant that he claims is easier to remember.<p>[0] <a href="http://en.wikipedia.org/wiki/Doomsday_rule" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Doomsday_rule</a><p>[1] <a href="http://www.timeanddate.com/date/doomsday-weekday.html" rel="nofollow">http:&#x2F;&#x2F;www.timeanddate.com&#x2F;date&#x2F;doomsday-weekday.html</a>