Doomsday rule: Difference between revisions
Content deleted Content added
Added Wren |
Not a robot (talk | contribs) Add BASIC and BCPL |
||
Line 58: | Line 58: | ||
* [https://www.archim.org.uk/eureka/archive/Eureka-36.pdf Tomorrow is the Day After Doomsday (p.28)] |
* [https://www.archim.org.uk/eureka/archive/Eureka-36.pdf Tomorrow is the Day After Doomsday (p.28)] |
||
=={{header|BASIC}}== |
|||
Note that 1/6/1800 is actually a Monday, not a Sunday. As far as I can tell this is actually the correct day. |
|||
<lang BASIC>10 DIM D$(7): FOR I=1 TO 7: READ D$(I): NEXT I |
|||
20 DIM D(12,1): FOR I=0 TO 1: FOR J=1 TO 12: READ D(J,I): NEXT J,I |
|||
30 READ Y: IF Y=0 THEN END ELSE READ M,D |
|||
40 PRINT USING "##/##/####: ";M;D;Y; |
|||
50 C=Y\100: R=Y MOD 100 |
|||
60 S=R\12: T=R MOD 12 |
|||
70 A=(5*(C AND 3)+2) MOD 7 |
|||
80 B=(S+T+(T\4)+A) MOD 7 |
|||
90 PRINT D$((B+D-D(M,-(Y MOD 4=0 AND (Y MOD 100<>0 OR Y MOD 400=0)))+7) MOD 7+1) |
|||
100 GOTO 30 |
|||
110 DATA Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday |
|||
120 DATA 3,7,7,4,2,6,4,1,5,3,7,5 |
|||
130 DATA 4,1,7,4,2,6,4,1,5,3,7,5 |
|||
140 DATA 1800,1,6, 1875,3,29, 1915,12,7, 1970,12,23 |
|||
150 DATA 2043,5,14, 2077,2,12, 2101,4,2, 0</lang> |
|||
{{out}} |
|||
<pre> 1/ 6/1800: Monday |
|||
3/29/1875: Monday |
|||
12/ 7/1915: Tuesday |
|||
12/23/1970: Wednesday |
|||
5/14/2043: Thursday |
|||
2/12/2077: Friday |
|||
4/ 2/2101: Saturday</pre> |
|||
=={{header|BCPL}}== |
|||
Note that 1/6/1800 is actually a Monday, not a Sunday. As far as I can tell this is actually the correct day. |
|||
<lang bcpl>get "libhdr" |
|||
let dayname(n) = |
|||
n = 0 -> "Sunday", |
|||
n = 1 -> "Monday", |
|||
n = 2 -> "Tuesday", |
|||
n = 3 -> "Wednesday", |
|||
n = 4 -> "Thursday", |
|||
n = 5 -> "Friday", |
|||
n = 6 -> "Saturday", |
|||
dayname(n rem 7) |
|||
let leap(year) = year rem 4 = 0 & (year rem 100 ~= 0 | year rem 400 = 0) |
|||
let weekday(y, m, d) = valof |
|||
$( let leapdoom = table 4,1,7,4,2,6,4,1,5,3,7,5 |
|||
let normdoom = table 3,7,7,4,2,6,4,1,5,3,7,5 |
|||
let c = y / 100 and r = y rem 100 |
|||
let s = r / 12 and t = r rem 12 |
|||
let an = (5 * (c rem 4) + 2) rem 7 |
|||
let doom = (s + t + (t/4) + an) rem 7 |
|||
let anchor = (leap(y) -> leapdoom, normdoom)!(m-1) |
|||
resultis (doom + d - anchor + 7) rem 7 |
|||
$) |
|||
let start() be |
|||
$( writef("January 6, 1800 was on a %S.*N", dayname(weekday(1800, 1, 6))) |
|||
writef("March 29, 1875 was on a %S.*N", dayname(weekday(1875, 3, 29))) |
|||
writef("December 7, 1915 was on a %S.*N", dayname(weekday(1915, 12, 7))) |
|||
writef("December 23, 1970 was on a %S.*N", dayname(weekday(1970, 12, 23))) |
|||
writef("May 14, 2043 will be on a %S.*N", dayname(weekday(2043, 5, 14))) |
|||
writef("February 12, 2077 will be on a %S.*N", dayname(weekday(2077, 2, 12))) |
|||
writef("April 2, 2101 will be on a %S.*N", dayname(weekday(2101, 4, 2))) |
|||
$)</lang> |
|||
{{out}} |
|||
<pre>January 6, 1800 was on a Monday. |
|||
March 29, 1875 was on a Monday. |
|||
December 7, 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 2, 2101 will be on a Saturday.</pre> |
|||