Doomsday rule: Difference between revisions

Content added Content deleted
m (typo)
(Add Factor)
Line 355: Line 355:
2/12/2077: Friday
2/12/2077: Friday
4/2/2101: Saturday</pre>
4/2/2101: Saturday</pre>

=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<lang factor>USING: accessors calendar calendar.english formatting
generalizations kernel math math.order math.vectors sequences ;

: check-year ( year -- ) ! months and days checked by <date>
1582 9999 between?
[ "Year must be between 1582 and 9999." throw ] unless ;

: doomsday ( year -- n )
{ 4 100 400 } [ mod ] with map { 5 4 6 } vdot 2 + 7 mod ;

: anchorday ( year month -- m )
1 - swap leap-year? { 4 1 } { 3 7 } ?
{ 7 4 2 6 4 1 5 3 7 5 } append nth ;

: weekday ( date -- str )
[ year>> dup check-year doomsday ] [ day>> + ]
[ dup year>> swap month>> anchorday - 7 + 7 mod ] tri
day-names nth ;

: test ( date -- )
[ "%B %d, %Y" strftime ]
[ now before? "was" "will be" ? ]
[ weekday ] tri
"%s %s on a %s.\n" printf ;

1800 1 6
1875 3 29
1915 12 7
1970 12 23
2043 5 14
2077 2 12
2101 4 2
[ <date> test ] 3 7 mnapply</lang>
{{out}}
<pre>
January 06, 1800 was on a Monday.
March 29, 1875 was on a Monday.
December 07, 1915 was on a Tuesday.
December 23, 1970 was on a Wednesday.
May 14, 2043 will be on a Thursday.
February 12, 2077 will be on a Friday.
April 02, 2101 will be on a Saturday.
</pre>


=={{header|FOCAL}}==
=={{header|FOCAL}}==