Created
August 16, 2019 15:39
-
-
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
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
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