我有计算正统复活节日期的代码,当我看到if-else部分时,它让我哭泣。请给出你的建议,如何使它发光(如果可能)。
我想我可以将日/月格式化为DateTime格式,但恐怕会带来更多的混乱。
通过这,它工作得很好。
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}."发布于 2014-10-29 17:48:24
完全未经测试的psuedo代码,但关键是实现f=从3月22日到东正教复活节的天数。
(* 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} 你也可以发到http://codegolf.stackexchange.com
https://codereview.stackexchange.com/questions/68263
复制相似问题