5
\$\begingroup\$

I have code for calculating the date for orthodox Easter and it makes me cry when I look at the 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<=9 
    easter = 22+f
    easter = easter + 13 if year > 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}."
\$\endgroup\$
2
\$\begingroup\$

Completely untested psuedo-code, but the key is to realize f = number of days from March 22 to Orthodox Easter.

(* 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} 

You might also post to http://codegolf.stackexchange.com

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.