r/dailyprogrammer • u/Coder_d00d 1 3 • Feb 18 '15
[2015-02-18] Challenge #202 [Intermediate] Easter Challenge
Description:
Given the year - Write a program to figure out the exact date of Easter for that year.
Input:
A year.
Output:
The date of easter for that year.
Challenge:
Figure out easter for 2015 to 2025.
34
Upvotes
5
u/[deleted] Feb 18 '15
One day, the programmer said, "I know, I'll use a regular expression." Now he had a list of easters!
C#. Kind of. I read half of the intro to the Wikipedia article on Computus and then came to my senses. This is how you're supposed to figure out when Easter is:
4
u/ChiefSnoopy Feb 18 '15 edited Feb 19 '15
Not a big fan of this question due to the nature of it. For basically anyone to do this, they'll go to Wikipedia and look up an algorithm regarding computus... Otherwise this is a daily math post, not so much a programming one. Just for the sake of doing it, though... here is mine in C using the Meeus Julian algorithm...
EDIT: Changed Gregorian to Julian to eliminate 13 day error.
3
u/G33kDude 1 1 Feb 18 '15 edited Feb 18 '15
Because there's no way I'd have ever been able to derive this, I just translated it from the python example on wikipedia. I might point out that trying to derive it yourself would be a terrible waste of time anyways; this is why we have the internet.
So here it is, my obligatory "solution" in AutoHotkey.
15
u/krismaz 0 1 Feb 19 '15 edited Feb 19 '15
Python3, with BeautifulSoup4:
Some nice people already made a website for this, and since everything is better online, we clearly need to use this existing publicly available microservice!
7
u/wizao 1 0 Feb 18 '15 edited Feb 18 '15
Haskell.
I kind of cheated because the standard time module already has gregorianEaster and orthodoxEaster.
Challenge:
Output:
The source code for those functions is very readable (as much as it can be)!
1
u/_morvita 0 1 Feb 19 '15
Python3, using PyEphem to calculate the dates of the full moon and VeryPrettyTable for output.
Output:
1
u/BayAreaChillin Feb 20 '15
Python. Did this in high school and still have no idea how this formula came about.
2
u/Godspiral 3 3 Feb 18 '15 edited Feb 18 '15
In J, Meeus Julian algo from wiki seemed shortest
2
u/codeman869 Feb 19 '15 edited Feb 19 '15
Ruby, almost went the online API route. Also, used the Gauß algorithm because it's more.... gangster.
2
u/[deleted] Feb 19 '15 edited Feb 19 '15
Of course I already submitted my C# solution, but here's one in Rust. Since Rust is (as far as I know) lacking any stable HTTP libraries I could use for my ... particular brand of "computation," I have--tragically!--been forced to actually calculate the date of Easter this time.
Full repository here: https://github.com/archer884/computus
My program uses the ever-popular anonymous Gregorian algorithm to calculate the date just one year at a time (in contrast to my C# app, which spat them all out at once), and the repo includes a shell script to run the program for the years 2015 through 2025.
2
u/ittybittykittyloaf Feb 19 '15
Python 3, 'borrowed' from wikipedia:
2
u/mrepper Feb 19 '15 edited Feb 21 '17
[deleted]
0.9418
2
u/pogotc 2 0 Feb 22 '15
Scala solution that gets the date from a website:
2
u/franza73 Feb 18 '15 edited Feb 20 '15
Here is a Perl one liner, that uses a library to solve the problem:
1
u/fvandepitte 0 0 Feb 18 '15
C++ using Meeus Julian algorithm
result:
1
u/frenkeld Feb 18 '15
Actually first post here. I used the Anonymous Gregorian algorithm to create it in Swift.
and the easter dates:
1
u/thegubble Feb 19 '15
Don't have time to factorize it down at work, but here is it in batch script. (You'll have to save it as a .bat file and run it)
1
u/Flaqq Feb 19 '15
Python 2.7
1
u/beforan Feb 19 '15
Lua 5.2
Output:
1
u/5k3l3t0r Feb 19 '15
I had to pick 2 challenges for my programming class at Seed Paths. This was one of them.<Enter> I wrote in C#:<Enter> public int GetEasterDay(int year) { // checks for the first day of April int day = 1; getDay = new DateTime(year, 4, day); while (getDay.DayOfWeek != DayOfWeek.Sunday) { day++; getDay = new DateTime(year, 4, day); } return day; }
1
u/5k3l3t0r Feb 19 '15 edited Feb 19 '15
<p>C# For my class at Seed Paths </p> <pre><code>public int GetEasterDay(int year) { // checks for the first day of April int day = 1; getDay = new DateTime(year, 4, day); while (getDay.DayOfWeek != DayOfWeek.Sunday) { day++; getDay = new DateTime(year, 4, day); } return day; }</code></pre>
1
u/theamusingnerd Feb 19 '15
Ruby http://pastebin.com/zd2yvjxh
1
u/stintose Feb 19 '15 edited Feb 19 '15
javaScript, following the "Anonymous Gregorian algorithm" aka "Meeus/Jones/Butcher" algorithm.
output:
1
u/curtmack Feb 19 '15 edited Feb 19 '15
Python
Okay, so, I didn't want to use one of the known algorithms because that's just cheating. But, at some point while digging through the mountains and mountains of obtuse and largely inaccurate information about the date of Easter, I decided to say fuck it and just calculate it the way they say it's calculated rather than the way it actually is calculated. So, here's a script that uses PyEphem to find the actual first Sunday after the actual first full moon after the actual vernal equinox, and skips all the controversy and bullshit:
This syncs with Western Easter about 91.7% of the time (sampled over the 600 years between 1700 and 2299). It fails in years where the full moon and the solstice lie close enough together that the church's weird ecclesiastical rules regarding paschal full moons and other such nonsense actually matter.
Edit: There's also some fuzziness going on because I'm using PyEphem to calculate the exact time and truncating the time information, even when that's wrong; for example, a full moon at 12:01 AM on March 21st would normally be considered a March 20th full moon. I think I can fix this.
Edit 2: It turns out that didn't actually matter for most of the errors, so never mind.
1
u/Quitechsol Feb 20 '15
Java. I'm not certain how date formatting works, I tried to do it a few times and ended up quite confused, so I set up a little printf... Feedback appreciated!
1
u/drstain Feb 20 '15
Java with joda:
1
u/shredder121 Feb 20 '15
First post, in Java (I recently dove into the java.time API for a library I contribute to).
Used the "good enough for these purposes" paschal full moon lookup and went from there.
Suggestions welcome of course.
Challenge output:
1
u/[deleted] Feb 20 '15
JavaScript
https://gist.github.com/anonymous/eaada6abb9bd25ec3ee9
Feedback would be appreciated
1
u/sprinky Feb 21 '15
PicoLisp once more.
Fortunately, there is already a function for algorithmically calculating Easter in one of the library files.
In the REPL:
1
u/fbWright Feb 21 '15
Forth (Gforth 0.7.0)
Just an implementation of the Butcher's algorithm (see this). Not idiomatic Forth, but it works.
1
u/jnazario 2 0 Feb 21 '15
late to the party, scala, translating the answer from /u/fvandepitte to scala.
1
u/[deleted] Feb 22 '15
Here's my solution in Swift, handcrafted with special sensitivity for non-Americans.
1
u/XDtsFsoVZV Feb 22 '15
Python 2.7
1
u/salgat Feb 23 '15
C
I just copied the algorithm found here, so it wasn't exactly a rewarding solution (I liked the beautifulsoup example, very practical even if it is a lot less "efficient").
1
u/hutcho66 Feb 25 '15 edited Feb 26 '15
Very late to the party, but here's my solution, using the Java Calendar class. Dates from 2015-2025 printed to the console using SimpleDateFormat. Algorithm is straight from https://www.assa.org.au/edm#Computer:
As a bonus, played around with Swing (still learning it) to ask for a year and then display the Easter date for the year to a window. The method is commented out in main.
1
u/JolleDEV Feb 25 '15 edited Feb 25 '15
According to php.net there's a function called easter_date() which makes it really easy to know when Easter is. I looped through the years 2015 to 2025.
PHP:
Output:
1
u/Atripes Feb 26 '15
C++
1
u/jeaton Feb 26 '15
Shell script and curl + grep:
1
u/thoth7907 0 1 Feb 26 '15
I went with the web approach as well, using PowerShell to retrieve the data and parse out the date.
1
u/urbanek2525 Feb 27 '15
F#
Figured since it is an implementation of a math formula, I'd try it in a functional language.
First time submitting and first time I've every tried F#. Please comment, especially if you're into functional programming in general or F# specifically.
1
u/[deleted] Mar 02 '15
Decided to give this a try in Java, using the anonymous Gregorian algorithm from the article linked in this thread!
Function:
Output:
1
u/[deleted] Apr 11 '15
C/C++
1
u/tassee Feb 18 '15
Python3.. weird 'question'.
0
u/[deleted] Feb 19 '15
[deleted] — view deleted comment