i cant think A blog belong to Mohammad Azwan bin Ali. Most of his writings are about his real life story, ideas, thoughts, moderate political views, computer, programming, tips & tricks, particularly in Linux…. and of course it includes some random unspecified crappy stuffs too! Don't forget to check Movies and Junkyard pages out!
note: most of entries is not suitable for faint hearted person or anybody with iq below 100.

calculating phase of moon in ruby

this is one of programmingpraxis exercise. written it in ruby because i need to sharpen my ruby skill :p

the question is quite easy actually. there's a lot more exciting and challenging excessive at programmingpraxis.com i will try during my free time. this can be some kind of new hobby i think...

  1. def julian (year, month, day)
  2. a = (14-month)/12
  3. y = year+4800-a
  4. m = (12*a)-3+month
  5. return day + (153*m+2)/5 + (365*y) + y/4 - y/100 + y/400 - 32045
  6. end
  7. def phase (year,month,day)
  8. p=(julian(year,month,day)-julian(2000,1,6))%29.530588853
  9. if p<1.84566: return "New"
  10. elsif p<5.53699: return "Waxing crescent"
  11. elsif p<9.22831: return "First quarter"
  12. elsif p<12.91963: return "Waxing gibbous"
  13. elsif p<16.61096: return "Full"
  14. elsif p<20.30228: return "Waning gibbous"
  15. elsif p<23.99361: return "Last quarter"
  16. elsif p<27.68493: return "Waning crescent"
  17. else return "New"
  18. end
  19. end
  20.  
  21. print "#{phase(2020,1,23)}\n"
  22. print "#{phase(1999,1,6)}\n"
  23. print "#{phase(2010,2,10)}\n"
  24. print "#{phase(1987,5,10)}\n"
  25.  

preview moon phase output


No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

:D [angely] [argh] [blindfold] [color] [cry] [bye] [cutie] [dance] [flirt] [ghost] [thumb] >_< hmmm more »