Talk:Day of the week: Difference between revisions

no edit summary
m (→‎Deleting examples: Fix OL hashes)
No edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 146:
Some other language implementations are using Zeller's congruence, too, so those may have the same problem.
<br>--[[User:PauliKL|PauliKL]] 16:30, 5 May 2009 (UTC)
 
=== TeX formula ===
<math>\begin{align}
adjustment = & \lfloor (14 - month) \div 12 \rfloor \\
mm = & month + 12 \times adjustment \\
yy = & year - adjustment \\
weekday \equiv & day + \lfloor (13 \times mm + 8) \div 5 \rfloor \\
& + yy + \lfloor yy \div 4 \rfloor
- \lfloor yy \div 100 \rfloor
+ \lfloor yy \div 400 \rfloor \mod 7 \\
\end{align}</math>
 
I wrote this [[metawikipedia:Help:Formula|TeX formula]] for Zeller's congruence, but decided not to put it on the page, so I saved it here. --[[User:Kernigh|Kernigh]] 21:43, 11 November 2011 (UTC)
 
== Deleting examples ==
Line 187 ⟶ 200:
:::# Trivial variations just for ego's sake -- I don't know. I can't define what "trivial" means within a language I don't know, and I know (through personal experience) that the word "trivial" is tied very closely to individual experience and competence. As long as the difference between two separate code examples can be described in meaningful terms, then I think there's likely to be value there--I can use those described differences in structuring the site and ''aiding'' browsability.
::: By and large, the installation of Semantic MediaWiki is intended to help address these problems, by making the wiki software aware of the differences between examples(what task, what language, what library, what paradigm), and allowing us to create navigation pages and shortcuts. --[[User:Short Circuit|Michael Mol]] 19:34, 1 August 2010 (UTC)
 
::Maybe we always have to take the complexity of the task being solved into account. For a simple task such as "Output the numbers 1 to five in order", you might expect an example using a for loop and another using a foreach loop, for example; as the way you loop is a large part of the task.
::For a larger task such as [[Range expansion]] you might prefer to work on the one example and edit it to come to a consensus on what looping structure to use. But an example picking and testing characters from a string might go ''alongside'' another example that parses using a regexp as the two methods are sufficiently different to be noteworthy.
::I don't know how to write the rules of noteworthiness other than by reading a lot of RC edits and looking at what happens. This will tend to perpetuate the status quo, however discussions like this pop up to help :-) (P.S. Edited simultaneousely with Michael's edit above. Written to follow the comment of Underscore)<br>--[[User:Paddy3118|Paddy3118]] 19:47, 1 August 2010 (UTC)
 
== Month contribution ==
Although date calculations don't usually need much optimization, it may be interesting to note that the division by 10 in Zeller's congruence (useful at Zeller time for hand calculations), can be replaced by a shift. Keeping only the interesting part, all it does is this :
 
Count days for 1st of each month, from 1st march, modulo 7 (in the following list, the third column is the number of days of the month, and the fourth is the cumulated number of days, mod 7, with a 1 month lag since march starts at day 0)
<lang>3 march 31 0
4 april 30 3 = 31 mod 7
5 may 31 5 = (31 + 30) mod 7
...
12 december 31 2 = (31 + 30 + ... + 30) mod 7 // the last in the sum is november, remember the lag
13 january 31 5 = ...
14 february -- 1 = ...</lang>
 
For february, one does not need to know the number of days, and it's precisely because it can change that we use a trick (year-1, month+12) to push it at the end of the list.
 
So, all one really needs is a mapping from (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) to (0, 3, 5, 1, 3, 6, 2, 4, 0, 2, 5, 1), possibly up to a constant, mod 7.
As we know from Zeller's congruence, '''floor((26*(m+1))/10)''' works perfectly well.
But so does '''floor((83*m+24)/32)''', and division by 32 is simply a shift.
Of course, there are many other values of A, B, C such that floor((A*m+B)/C) does the job, but 32 is the least power of 2 that works.
 
[[User:Dejvicka|Dejvicka]] 12:54, 22 September 2012 (UTC)
Anonymous user