Is there an easy way to determine if a year is a leap year?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- How to truncate seconds in TSQL?
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- How to remove seconds from datetime?
- Segmentation fault with ruby 2.0.0p247 leading to
- OLS with pandas: datetime index as predictor
Here is my answer for the exercism.io problem which asks the same question. You are explicitly told to ignore any standard library functions that may implement it as part of the exercise.
Any year that is evenly divisible by 4 is a leap year. However, there is still a small error that must be accounted for. To eliminate this error, the Gregorian calendar stipulates that a year that is evenly divisible by 100 (for example, 1900) is a leap year only if it is also evenly divisible by 400.
For your understanding:
This could be written as: