Talk:Day of the week: Difference between revisions

no edit summary
No edit summary
 
(10 intermediate revisions by 5 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 155 ⟶ 168:
 
:: The thing that bothered me about the removal was that it went from several examples showing at least a couple different approaches and coding styles to just one examples. That rather defeats Perl's TMTOWTDI philosophy, IMO. --[[User:Short Circuit|Michael Mol]] 02:57, 31 July 2010 (UTC)
::: Maybe a mention of TMTOWTDI on RC's main Perl page and mention of its implications w.r.t. RC? --[[User:Paddy3118|Paddy3118]] 04:26, 31 July 2010 (UTC)
 
Also, DateTime is not a core module, so is inferior in many ways compared to the deleted example which uses Time::Local, which ''is'' a core module (i.e., included with Perl). --[[Special:Contributions/71.141.117.11|71.141.117.11]] 04:00, 31 July 2010 (UTC)
: Seems like you have a reason to leave the Time::Local version in fully and just maybe mention the existence of DateTime?<br> P.S. I should mention that I am a reluctant Perl programmer --[[User:Paddy3118|Paddy3118]] 04:26, 31 July 2010 (UTC)
 
Thanks, guys. I'm still a RC n00b, so I flagged my undo here and I leave it up to your wiser heads to decide. BTW, the examples were not my code, so I have no vested interest. I think ShinTakezou was the original poster.
 
> When constrained, how do Perl users wish their language to be seen when there are differing levels of concise-ness available
 
That's a very interesting question. I've been out of Perl culture for a while, so I'm not sure how it has evolved. Perl is famous for "golf" solutions - tight, elegant, and unreadable. But stylistically, Perl is less constrained than some other languages and open to more conventional approaches as well. My impression is that RC is supposed to be pedagogically useful, as well as a place to show off one's code-fu. So allowing less concise solutions to stand may sometimes be helpful.
 
I've already seen a few instances where the Perl Patrol have come in and re-written code for what seem to be mostly personal style preferences, e.g. my $foo = shift vs. my $foo = $_[0]. So I agree that this might be a useful discussion on the Perl page, and maybe some kind of consensus might emerge. Especially with Perl 6 looming, and the first official non-dev release of Perl 6 "Rakudo Star" only yesterday.
 
Fortunately, given the number of Snobol programmers out there, I'd guess my main Snobol4 contributions so far are less likely to be rewritten. :-) --[[User:Snoman|Snoman]] 05:58, 31 July 2010 (UTC)
 
I removed the <code>Time::Local</code> version because it doesn't work because on 32-bit machines due to the year 2038 problem (look at the sample output). I removed another two examples because they varied from the last example only in ways that had nothing to do with the task. I'm a big believer in TIMTOWTDI, but I see the idea behind that principle being that you can pick whatever method you like, not that you should pick multiple redundant methods. It seems obvious to me that when multiple solutions are provided for a single language, they should vary in ways that are ''relevant to the task''—see, for example, how so many languages have multiple solutions for [[Fibonacci sequence]], since (a) the task is understood to be a demonstration of looping, so showing how your language does iteration and recursion is wholly appropriate, and (b) there are a number of drastically different alternative approaches. If we allow those three different versions of essentially the same program here, I see no argument why every Perl program in Rosetta Code that has a while loop couldn't be accompanied by a nearly identical version that uses an until loop. Let's try to keep the signal-to-noise ratio high. —[[User:Underscore|Underscore]] ([[User talk:Underscore|Talk]]) 22:27, 31 July 2010 (UTC)
 
:Thanks, I've learned something more today. So maybe keep '''a''' DateTime version, together with a note that it is on CPAN and that built-in Time::Local is not being used due to these problems on 32 bit machines? --[[User:Paddy3118|Paddy3118]] 23:50, 31 July 2010 (UTC)
:: Sounds good to me. —[[User:Underscore|Underscore]] ([[User talk:Underscore|Talk]]) 18:20, 1 August 2010 (UTC)
 
:I don't at all like examples and snippets being removed from RC, as long as the code is legal (copyright caveat, etc). That said, with the site's current organization, I can understand why it would be a problem if there were thirty examples for Ayrch for each task, but only a relatively small number for other languages.
 
:Rosetta Code's core mission approach is helping people learn tool X by looking at tool X applied alongside more familiar tools Y and Z. A tool can be a language, a library, a programming paradigm or a language features (consider the scenario of showing how to do memory-management relevant things in a language with ''optional'' garbage collection). To that end, it's practical to apply learning-by-comparison within a language, such as demonstrating '''for''' against '''foreach''' against '''map'''.
 
:"Picking whatever method you like" is a matter for the individual contributor and the individual user of the language, but when Rosetta Code is being used as a learning resource, it becomes important to avoid hiding language capabilities.
 
:Again, I can understand why that could be a problem, given the way the site is currently structured with monolithic task pages. Migrating toward the Semantic MediaWiki feature set should allow us to clean and organize things in a more fine-grained fashion, such as by allowing individual code examples to be tagged with the language features they exploit. --[[User:Short Circuit|Michael Mol]] 13:54, 1 August 2010 (UTC)
:: Don't you fear that a don't-delete-stuff-so-long-as-it's-legal strategy could lead to good code getting lost in crufty, mediocre code, and to people adding trivial variations just for ego's sake? This isn't the first time that I deleted something for the sake of improving the site. —[[User:Underscore|Underscore]] ([[User talk:Underscore|Talk]]) 18:20, 1 August 2010 (UTC)
:::# Crufty, mediocre code -- We already have that, even in areas without apparent redundancy. ''Every'' time I see RC linked to from Reddit, ycombinator or some other geek link aggregate-and-comment place, I see complaints about the code quality not being that great. That's why we have [[Template:incorrect]] and other ENAs. I've been investigating ways of automating some components of code review to help maintain and improve quality.
:::# Code getting lost -- Not especially, particularly if a language's multiple tacks on the same task can be differentiated by approach, illustrating different ways the language can be used. I ''especially'' expect to see multiple-tacks taken as more third-party libraries are demonstrated. DirectX vs OpenGL vs SDL, DirectComputer versus CUDA vs OGL4, Linux's ALSA vs SDL vs POSIX's OSS vs Win32's WaveOut. Language/Task isn't the only pair of intersections I want or expect to see Rosetta Code implement.
:::# 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