Skip to content

Instantly share code, notes, and snippets.

@gouf
Created August 16, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gouf/c06273bdcd2beb05d2ac226dd055f9d1 to your computer and use it in GitHub Desktop.
Save gouf/c06273bdcd2beb05d2ac226dd055f9d1 to your computer and use it in GitHub Desktop.
Paiza レベルアップ問題集: 「月の日数 Ruby編」 - https://paiza.jp/works/mondai/dateset/ruby/days_in_a_month
require 'date'
def count_day_in_month(date, month:, count: 0)
return count unless month.eql?(date.month)
count_day_in_month(date.succ, month: month, count: count + 1)
end
year, month, day = [*gets.chomp.split, 1].map(&:to_i)
puts count_day_in_month(Date.new(year, month, day), month: month)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment