patternrubyMinor
Orthodox Easter calculator
Viewed 0 times
calculatororthodoxeaster
Problem
I have code for calculating the date for orthodox Easter and it makes me cry when I look at the
I guess I can format day/month to DateTime format but I'm afraid it'll bring just more mess.
It works just fine though this.
Source
if-else part. Please give your suggestions on how to make it shine (if possible).I guess I can format day/month to DateTime format but I'm afraid it'll bring just more mess.
It works just fine though this.
Source
puts "- Hello, I'm EasterEvaluator. I can tell you when will be(or was) Easter."
puts "- Please enter the year which you'r interested in:"
year = gets.chomp.to_i
a = year % 19
b = year % 4
c = year % 7
d = (19*a+15) % 30
e = (2*b + 4*c + 6*d + 6) % 7
f = d + e
if f 1918
if easter > 31
easter = easter - 31
month = "April"
else
month = "March"
end
else
easter = f-9
easter = easter + 13 if year > 1918
if easter > 30
easter = easter-30
month = "May"
else
month = "April"
end
end
puts "- In #{year}, Easter is going to be on #{easter} of #{month}."Solution
Completely untested psuedo-code, but the key is to realize f = number of days from March 22 to Orthodox Easter.
You might also post to http://codegolf.stackexchange.com
(* f gives Easter as the number of days since March 22 *)
easter = f+22+(year 31 {month="April"; day=f-31}
if f > 61 {month="May"; day=f-61}You might also post to http://codegolf.stackexchange.com
Code Snippets
(* f gives Easter as the number of days since March 22 *)
easter = f+22+(year<1918)*13
month = "March"; # default
if f > 31 {month="April"; day=f-31}
if f > 61 {month="May"; day=f-61}Context
StackExchange Code Review Q#68263, answer score: 2
Revisions (0)
No revisions yet.