Day of the week of Christmas and New Year: Difference between revisions
(Tidied task description.) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
||
Line 24: | Line 24: | ||
Next new year is on a Sunday |
Next new year is on a Sunday |
||
</pre> |
</pre> |
||
=={{header|Raku}}== |
|||
<lang perl6>my @d-o-w = < Sunday Monday Tuesday Wednesday Thursday Friday Saturday >; |
|||
.say for (flat 2020..2022, (1500 .. 2500).roll(7)).sort.map: { |
|||
"In {$_}, New Years is on a { @d-o-w[Date.new($_, 1, 1).day-of-week % 7] }, " ~ |
|||
"and Christmas on a { @d-o-w[Date.new($_, 12, 25).day-of-week % 7] }." |
|||
}</lang> |
|||
{{out|Sample output}} |
|||
<pre>In 1578, New Years is on a Sunday, and Christmas on a Monday. |
|||
In 1590, New Years is on a Monday, and Christmas on a Tuesday. |
|||
In 1642, New Years is on a Wednesday, and Christmas on a Thursday. |
|||
In 1957, New Years is on a Tuesday, and Christmas on a Wednesday. |
|||
In 2020, New Years is on a Wednesday, and Christmas on a Friday. |
|||
In 2021, New Years is on a Friday, and Christmas on a Saturday. |
|||
In 2022, New Years is on a Saturday, and Christmas on a Sunday. |
|||
In 2242, New Years is on a Saturday, and Christmas on a Sunday. |
|||
In 2245, New Years is on a Wednesday, and Christmas on a Thursday. |
|||
In 2393, New Years is on a Friday, and Christmas on a Saturday.</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
Revision as of 14:17, 24 November 2021
- Task
Determine programatically and show on this page on what weekday Christmas Day, 2021 and New Year's Day, 2022 will fall or did fall.
Python
<lang python> iimport datetime
weekDays = ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") thisXMas = datetime.date(2021,12,25) thisXMasDay = thisXMas.weekday() thisXMasDayAsString = weekDays[thisXMasDay] print("This year's Christmas is on a {}".format(thisXMasDayAsString))
nextNewYear = datetime.date(2022,1,1) nextNewYearDay = nextNewYear.weekday() nextNewYearDayAsString = weekDays[nextNewYearDay+1] print("Next new year is on a {}".format(nextNewYearDayAsString)) </lang>
- Output:
This year's Christmas is on a Saturday Next new year is on a Sunday
Raku
<lang perl6>my @d-o-w = < Sunday Monday Tuesday Wednesday Thursday Friday Saturday >;
.say for (flat 2020..2022, (1500 .. 2500).roll(7)).sort.map: {
"In {$_}, New Years is on a { @d-o-w[Date.new($_, 1, 1).day-of-week % 7] }, " ~ "and Christmas on a { @d-o-w[Date.new($_, 12, 25).day-of-week % 7] }."
}</lang>
- Sample output:
In 1578, New Years is on a Sunday, and Christmas on a Monday. In 1590, New Years is on a Monday, and Christmas on a Tuesday. In 1642, New Years is on a Wednesday, and Christmas on a Thursday. In 1957, New Years is on a Tuesday, and Christmas on a Wednesday. In 2020, New Years is on a Wednesday, and Christmas on a Friday. In 2021, New Years is on a Friday, and Christmas on a Saturday. In 2022, New Years is on a Saturday, and Christmas on a Sunday. In 2242, New Years is on a Saturday, and Christmas on a Sunday. In 2245, New Years is on a Wednesday, and Christmas on a Thursday. In 2393, New Years is on a Friday, and Christmas on a Saturday.
Wren
<lang ecmascript>import "./date" for Date
var xmas = Date.new(2021, 12, 25) // xmas and new year's weekdays are always the same var weekday = xmas.weekDay System.print("Christmas day, 2021 will fall on %(weekday).") System.print("New year's day, 2022 will also fall on %(weekday).")</lang>
- Output:
Christmas day, 2021 will fall on Saturday. New year's day, 2022 will also fall on Saturday.