Skip to content

Instantly share code, notes, and snippets.

@sugamasao
Created July 31, 2013 16:21
Show Gist options
  • Save sugamasao/6123571 to your computer and use it in GitHub Desktop.
Save sugamasao/6123571 to your computer and use it in GitHub Desktop.
うるう年の計算してみたよ start_year から end_yearまでの間でうるう年の年を出力する
# ruby leap_year.rb 2000 2100
start_year = ARGV[0].to_i
end_year = ARGV[1].to_i
def leap_year?(year)
if (year % 400).zero?
true
elsif !(year % 100).zero? && (year % 4).zero?
true
end
end
start_year.upto(end_year) do |year|
puts year if leap_year?(year)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment