Skip to content

Instantly share code, notes, and snippets.

@certainty
Created September 18, 2015 06:22
Show Gist options
  • Save certainty/cf13a1a4d2fcc2ade6f6 to your computer and use it in GitHub Desktop.
Save certainty/cf13a1a4d2fcc2ade6f6 to your computer and use it in GitHub Desktop.
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