TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Lewis Carroll – computing the day of the week for any given date (1887)

199 pointsby beardywabout 1 year ago

19 comments

ColinWrightabout 1 year ago
This is very similar to the method I use and, after conversation with him, the method Art Benjamin uses. It&#x27;s trivial to do in 10 to 15 seconds, though it requires practice, a very small amount of memorisation[0], and a small amount of mental arithmetic. I use it regularly, partly to keep in practice, and partly because once you have the skill you find it&#x27;s surprisingly useful.<p>JH Conway used a different technique[1] which I have swutch to when computing days in the current year. It&#x27;s quicker and easier, but I find that it&#x27;s harder to compute &quot;The Doomsday&quot; for other years (it&#x27;s Thursday this year), so I revert to my standard method[2].<p>Example: Today is 2024&#x2F;05&#x2F;24<p><pre><code> Years since 2012 is 12 Leap years is 12&#x2F;4 = 3 Magic month number = 2 Date is 24 Add mod 7 is (12+3+2+24) = (-2)+3+2+3 = 6 = Friday </code></pre> [0] A &quot;magic number&quot; for each month. There are mnemonics, and they can be computed from first principles if needed. It&#x27;s also easy to remember a few and then compute the others.<p><pre><code> 144 : Jan, Feb, Mar 025 : Apr, May, Jun 036 : Jul, Aug, Sep 146 : Oct, Nov, Dec </code></pre> [1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Doomsday_rule" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Doomsday_rule</a><p>[2] All values computed mod 7. Take years since 1900. Add number of leap years since 1900 (so (YYYY-1900)&#x2F;4 rounded down). Add the magic number for the month. Add the day of the month. Then Sunday=1, Wednesday=4, etc.<p>Because the calendar repeats every 28 years, for more recent dates you can start with 2012 instead of 1900.
评论 #40464703 未加载
评论 #40464737 未加载
评论 #40472071 未加载
评论 #40470055 未加载
评论 #40464842 未加载
评论 #40471183 未加载
评论 #40464911 未加载
评论 #40474693 未加载
评论 #40471528 未加载
评论 #40471507 未加载
评论 #40472228 未加载
评论 #40471484 未加载
评论 #40469515 未加载
评论 #40466415 未加载
评论 #40468215 未加载
评论 #40468651 未加载
评论 #40464702 未加载
throwaway211about 1 year ago
Reading the article, I wandered into the difference of Old Style and New Style dates and what happened in 1752.<p>From [1]: By the 18th century, the English legal year – used for legal, financial and other civil purposes – had for centuries begun on 25 March, or Lady Day.[13][i] Thus, for example, 24 March 1707 was immediately followed by 25 March 1708, while the day following 31 December 1708 was 1 January 1708, with 1709 still nearly three months away.<p>Thank goodness that happened.<p>[1] <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Calendar_(New_Style)_Act_1750#New_Year&#x27;s_Day" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Calendar_(New_Style)_Act_175...</a>
评论 #40467351 未加载
评论 #40470268 未加载
评论 #40467277 未加载
评论 #40469065 未加载
评论 #40466485 未加载
评论 #40465623 未加载
thyrsusabout 1 year ago
I&#x27;m having trouble following the algorithm for the month number.<p>From the article:<p>The Month-Item. — If it begins or ends with a vowel, subtract the number, denoting its place in the year, from 10. This, plus its number of days, gives the item for the following month. The item for January is ‘0’; for February or March (the 3rd month), ‘3’; for December (the 12th month), ’12.’ [So, for clarity, the required final numbers after division by 7 are January, 0; February, 3; March, 3; April, 6; May, 1; June, 4; July, 6; August 2; September, 5; October, 0; November, 3; and December, 5.]<p>My attempt to implement:<p>For January, the preceding month is December, which neither begins nor ends with a vowel, so I do not subtract 10. The days in December are 31, so 12+31 = 43 mod 7 = 1, not the 0 of the article.<p>For February, the preceding month is January, which ends in a vowel, so I subtract 1 from 10, giving 9, add the days in January 1+31 = 32 mod 7 = 4, not the 3 of the article.<p>For March, the preceding month is February, which ends in a vowel, so I subtract 2 from 10 giving 8 and add February&#x27;s 28 days 8+28 = 36 mod 7 = 1, not the 3 of the article. Had I used a leap year 29 for the days in February at this step the result would be 2, which still does not match the article result. Since the article has a constant result for March, it is either always using 28 or always using 29 days in February.<p>For April, the preceding month is March, which neither begins nor ends in a vowel so I do not subtract it from 10. 31 days in March gives 3+31 = 34 mod 7 = 6, which does match the article result.<p>For May, the preceding month is April, which starts with a vowel, so I subtract its position from 10, 10-4 = 6, add April&#x27;s 30 days 6+30 = 36 mod 7 = 1 which does match the article.<p>For June, the preceding month is May, ending in a vowel, so I subtract May&#x27;s 5 from 10, and adding May&#x27;s 31 days gives 5+31= 36 mod 7 = 1 which does not match the article.<p>This should suffice to illustrate my misunderstanding; what have I got wrong?<p>[edit: typos]
评论 #40467992 未加载
评论 #40467181 未加载
评论 #40467774 未加载
bumbledravenabout 1 year ago
Carroll&#x27;s algorithm has evolved over the years. The First Sunday Doomsday Algorithm (<a href="https:&#x2F;&#x2F;firstsundaydoomsday.blogspot.com&#x2F;2009&#x2F;12&#x2F;quick-start-guide.html" rel="nofollow">https:&#x2F;&#x2F;firstsundaydoomsday.blogspot.com&#x2F;2009&#x2F;12&#x2F;quick-start...</a>) includes all the improvements published as of 2023, including Fong &amp; Walters&#x27; nifty &quot;odd+11&quot; rule for calculating the year code (<a href="https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1010.0765" rel="nofollow">https:&#x2F;&#x2F;arxiv.org&#x2F;abs&#x2F;1010.0765</a>).
gcanyonabout 1 year ago
I did a write-up of (what I think is) a more straightforward way to do this here: <a href="https:&#x2F;&#x2F;gcanyon.wordpress.com&#x2F;2013&#x2F;04&#x2F;09&#x2F;a-better-way-to-calculate-the-day-of-the-week&#x2F;" rel="nofollow">https:&#x2F;&#x2F;gcanyon.wordpress.com&#x2F;2013&#x2F;04&#x2F;09&#x2F;a-better-way-to-cal...</a>
ColinWrightabout 1 year ago
It&#x27;s really interesting watching Art Benjamin do this in his TED talk[0] ... if you watch closely you can see him keeping track of the intermediate calculations in his hand movements.<p>Very clever, and obvious once you know.<p>[0] <a href="https:&#x2F;&#x2F;www.ted.com&#x2F;talks&#x2F;arthur_benjamin_a_performance_of_mathemagic" rel="nofollow">https:&#x2F;&#x2F;www.ted.com&#x2F;talks&#x2F;arthur_benjamin_a_performance_of_m...</a> ... starts at 7:47
SamBamabout 1 year ago
So Lewis Carroll&#x27;s method for today (May 24 2024):<p>The Century-Item:<p>The year is 2024. The century is 20.<p>20&#x2F;4 = 5, with no remainder. Overplus is 0. 3-0 = 3. 3x2 = 6.<p>The Year-Item:<p>The year part is 24. Number of dozens: 2<p>24&#x2F;12=2. Overplus: 24 mod 12 = 0. Number of 4&#x27;s in the overplus: 0. 2+0+0 = 2.<p>The Month-Item: May: 1 (from the text).<p>The Day-Item: The day is 24.<p>Adding all items:<p>6+2+1+24=33. 33 mod 7 = 5, which is Friday.
评论 #40467555 未加载
llm_trwabout 1 year ago
To people who say that notation doesn&#x27;t matter, this is what all mathematics was like before we got our new better notation.<p>I&#x27;d go as far as saying that in mathematics little other than notation matters and the same is true in computer science.<p>This is why lisp like languages are the obvious choice when variables are explicit.
评论 #40467354 未加载
beardywabout 1 year ago
If he could do it in 20 seconds I would call that remarkable!<p>He didn&#x27;t consider himself a &quot;rapid computer&quot;.
评论 #40464857 未加载
Jimmc414about 1 year ago
# (jim) C:\Users\Jim&gt;python dow.py<p># Enter a date (yyyy-mm-dd): 2024-05-24<p># The day of the week for 2024-05-24 is Friday.<p>def compute_day_of_week(date):<p><pre><code> day, month, year = date century = year &#x2F;&#x2F; 100 year_part = year % 100 # Compute Century-Item if year &lt; 1752 or (year == 1752 and (month &lt; 9 or (month == 9 and day &lt; 14))): century_item = (18 - century) % 7 else: century_item = ((3 - (century % 4)) * 2) % 7 # Compute Year-Item year_item = (year_part + (year_part &#x2F;&#x2F; 4)) % 7 # Compute Month-Item month_items = [0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5] month_item = month_items[month - 1] # Compute Day-Item day_item = day % 7 # Total total = (century_item + year_item + month_item + day_item) % 7 # Correction for Leap Year if month &lt;= 2 and (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)): total = (total - 1 + 7) % 7 return total </code></pre> def day_of_week_string(day_index):<p><pre><code> days = [&quot;Sunday&quot;, &quot;Monday&quot;, &quot;Tuesday&quot;, &quot;Wednesday&quot;, &quot;Thursday&quot;, &quot;Friday&quot;, &quot;Saturday&quot;] return days[day_index] </code></pre> # Prompt for the date<p>date_input = input(&quot;Enter a date (yyyy-mm-dd): &quot;)<p>year, month, day = map(int, date_input.split(&#x27;-&#x27;))<p>date = (day, month, year)<p># Compute and print the day of the week<p>day_index = compute_day_of_week(date) day_name = day_of_week_string(day_index) print(f&quot;The day of the week for {date_input} is {day_name}.&quot;)
评论 #40472722 未加载
hasbriwn23about 1 year ago
I made an app to learn this - <a href="https:&#x2F;&#x2F;grantas33.github.io&#x2F;Doomsday-algorithm-practice&#x2F;" rel="nofollow">https:&#x2F;&#x2F;grantas33.github.io&#x2F;Doomsday-algorithm-practice&#x2F;</a>
bee_riderabout 1 year ago
What a pain.<p>We really should just declared the year to be 360 days long, with 12 months, 30 days each, split into 6 day long weeks. The extra 5 days? Everybody take a vacation. Leap days go in there too somehow. Every month starts with a Monday and ends with a Sunday. Wednesday will be removed because it was no good anyway.
评论 #40470738 未加载
nfw2about 1 year ago
You would think a professional writer would be able to describe straightforward arithmetic in a coherent way.
tzsabout 1 year ago
For the part that depends on the last two digits of the year I use a method that I&#x27;ve not seen anywhere else. It is algorithmically more work than Conway&#x27;s method (Y + Y&#x2F;&#x2F;4, where Y is the last two digits of the year and &#x2F;&#x2F; is integer division rounding positive results down), but I think is easier for quick mental computation for most people.<p>Let Y = 10 T + U, i.e., T is the first digit of the two digit year and U is the second digit.<p>If T is even, the year part is:<p><pre><code> 2 T + U if U = 0, 1, 2, or 3 2 T + U + 1 if U = 4, 5, 6, or 7 2 T + U + 2 if U = 8 or 9 </code></pre> If T is odd:<p><pre><code> 3 + 2 T + U if U = 0 or 1 3 + 2 T + U + 1 if U = 2, 3, 4, or 5 3 + 2 T + U + 2 if U = 6, 7, 8 or 9 </code></pre> Algorithmically I compute it something like this:<p><pre><code> Compute 2 T + U If T is even Add 1 if T &gt;= 4 and add another 1 if T &gt;= 8 else Add 3 Add 1 if T &gt;= 2 and add another 1 if T &gt;= 6 </code></pre> Those add 1s come from the way leap years are distributed within decades. The 2 T + U takes into account any leap years when U = 0. The add 1s are to take care of the leap years that happen when U != 0. In even decades those occur at 4 and 8, and in odd decades they occur at 2 and 6.<p>Example: for 2024, T=2 and U=4. Mentally my train of thought would be:<p><pre><code> 2 doubles to 4, plus 4 = 8 = 1 mod 7, even decade so add 1 for 4 &lt;= T &lt; 8 giving 2. </code></pre> For that example there is not really easier than Conway&#x27;s Y + Y&#x2F;&#x2F;4, which would be 24 + 6 = 30 = 2 mod 7.<p>Example: for 2099, T = 9 and U = 9. Mentally that goes something like this:<p><pre><code> 9 = 2 mod 7 doubles to 4, add 9 = 2 mod 7 giving 6 T was odd so add 3 giving 9 = 2 mod 7 T was odd so the so there were leap years at 2 and 6, which each add 1 That gives us 4 </code></pre> I find that easier that Conway&#x27;s 99 + 99&#x2F;4. I can do that, and at decent speed, but I can make mistakes.<p>With my method you never have to deal with a number above 32, and that&#x27;s only if you do no reductions mod 7 along the way. If you reduce mod 7 whenever you can you never have to deal with anything above 12.<p>Note: when reducing mod 7 along the way it is crucial to remember that whether you take the T is even case or the T is odd case depends on the actual value of T. E.g., when I am doing 2099 I reduce both T and U to 2 right away but first note that 9 is odd so will need to take the odd case.
roland35about 1 year ago
This is why we need the international fixed calendar!!<p><a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;International_Fixed_Calendar" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;International_Fixed_Calendar</a>
shhsshsabout 1 year ago
<a href="https:&#x2F;&#x2F;benjoffe.com&#x2F;weekle" rel="nofollow">https:&#x2F;&#x2F;benjoffe.com&#x2F;weekle</a>
ot1138about 1 year ago
Neat but what is this useful for?
评论 #40468308 未加载
评论 #40466023 未加载
brcmthrowawayabout 1 year ago
Can an LLM come up with a novel algorithm for this?
doubloonabout 1 year ago
plenty of non-pedophiles did a lot more interesting work, not sure why we have to even mention him.