開源日報 每天推薦一個 GitHub 優質開源項目和一篇精選英文科技或編程文章原文,堅持閱讀《開源日報》,保持每日學習的好習慣。
今日推薦開源項目:《羅伯特 robocode》
今日推薦英文原文:《How to Perform Calendar Calculations in Your Head》

今日推薦開源項目:《羅伯特 robocode》傳送門:GitHub鏈接
推薦理由:程序員之間對上眼的時候就要來一場戰鬥——當然了,並沒有人這麼說過。不過如果你真的想要用代碼來戰鬥,這個項目興許能夠滿足你。你可以在這個項目里創造一架跑著自己寫的代碼的機器人,通過調用各種函數來進行各種操作最後射爆場上的所有人。說著很簡單,但是如果融入自己所學的各種演算法等等之後,每個人的機器人都會大不相同,團建什麼的時候自然可以拿這個來讓大家互相打一架。
今日推薦英文原文:《How to Perform Calendar Calculations in Your Head》作者:Jørgen Veisdal
原文鏈接:https://medium.com/cantors-paradise/how-to-perform-calendar-calculations-5617f35d3070
推薦理由:算出某一天是星期幾的算式,雖然可能比較慢……

How to Perform Calendar Calculations in Your Head

A so-called calendrical savant (or calendar savant) is someone who despite their intellectual disability (typically autism) can name the day of the week of a given date, or visa versa in a few seconds or even a tenth of a second (Kennedy & Squire, 2007).While extremely impressive to behold, calendar calculations are actually very simple to perform and can be learned in less than 30 minutes. This short article will teach you how.

What day was the 13th of January 1989?

My birthday. I was born two weeks late. Here is how to calculate which day of the week that was (Lancaster, 2005):

Step 1. Calculate the Year Code Y

The first step of our five step process is to calculate the year code, represented by the letter Y. This is done in the following way:
Calculate the Year Code Y
Take the last two digits of the year, divide by 4, remove the remainder. For my birthday, 89 / 4 = 22. Add the number to the last two digits of the year, 22 + 89 = 111For dates in the 1700s, add 4.
For dates in the 1800s, add 2.
For dates in the 1900s, add 0.
For dates in the 2000s, add 6.
For dates in the 2100s, add 4.
So, for the date 13th of January 1989 we obtain the year code Y =111.

Step 2. Find the Month Code M

The second step of our five step calculation is to find the month code M. This is a simple step, simply look it up in the table below (or better, memorize it):
Month        Code 
January      1*
February     4*
March        4
April        0
May          2
June         5
July         0
August       3
September    6
October      1
November     4
December     6If the year you are calculating for is/was a leap year, subtract 1 from the code for January and February, so January = 0 and February = 3.
As we know, leap years occur every four years (even years). Century years like 1900, 2000 and 2100 are leap years if they are evenly divisible by 400.

For the date 13th of January 1989, we obtain the month code M = 1.

Step 3. Find the Day Code D

The third step of our five step calculation is to find the day code D. This iS even easier than finding the month code, as it is simply the number of the date itself. For the 13th of January 1989, the number is D = 13.

Step 4. Find the sum of the numbers Y + M + D

The fourth step of our five step model is to add the three numbers we』ve found. For our three numbers, the sum is 111 + 1 + 13 = 125.

Step 5. Find the Day of the week

The final step of the calculation is to calculate the remainder of the modulo operation 125 mod 7. We know that 7 x 17 is 119, leaving a remainder of 6:
Day         Remainder
Saturday    0
Sunday      1
Monday      2
Tuesday     3
Wednesday   4
Thursday    5
Friday      6
The 13th of January 1989 was a Friday. Yes, I was born on Friday the 13th.
下載開源日報APP:https://openingsource.org/2579/
加入我們:https://openingsource.org/about/join/
關注我們:https://openingsource.org/about/love/