require 'date'
=begin
This program determines the day of the week for January 1st of a given year.
Approach:
---------
Ruby provides built‑in date/time handling through the Date class:
- Date.new(year, month, day) : constructs a calendar date
- date.wday : returns weekday number (0..6)
- date.strftime("%A") : returns full weekday name ("Thursday")
wday meaning:
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday
This avoids manual calendar arithmetic and uses efficient built‑in routines.
=end
# Convert a Date object's weekday to a readable string
def weekday_name(date_obj)
date_obj.strftime("%A") # "Monday", "Tuesday", ..., "Sunday"
end
# Compute weekday of January 1st for a given year
def jan1_weekday(year)
date_value = Date.new(year, 1, 1) # January 1st of given year
weekday_name(date_value)
end
year = 2026
result = jan1_weekday(year)
puts "January 1st, #{year} falls on a #{result}."
=begin
run:
January 1st, 2026 falls on a Thursday.
=end