Created
September 18, 2015 06:22
-
-
Save certainty/cf13a1a4d2fcc2ade6f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def leap_year?(year) | |
year.modulo(400).zero? || year.modulo(4).zero? && !year.modulo(100).zero? | |
end | |
def leap_years(range = 1..Float::INFINITY) | |
range.lazy.select(&method(:leap_year?)) | |
end | |
# Examples | |
leap_years.take(20).to_a | |
leap_years(1900..2020).to_a | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment