Day of the week: Difference between revisions
Added MiniScript
m (review RPL comments) |
(Added MiniScript) |
||
(11 intermediate revisions by 9 users not shown) | |||
Line 944:
==={{header|Minimal BASIC}}===
{{works with|IS-BASIC}}
<syntaxhighlight lang="gwbasic">10 REM Find years with Sunday Christmas
20 LET F = 2008
30 LET T = 2121
Line 958 ⟶ 957:
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
==={{header|MSX Basic}}===
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">10 REM Find years with Sunday Christmas
11 CLS
20 LET F = 2008
30 LET T = 2121
40 PRINT "Sunday Christmases"; F; "-"; T
50 PRINT
60 FOR Y = F TO T
70 LET E = Y * 365 + INT(Y/4) - INT(Y/100) + INT(Y/400)
80 LET X = E - 6
90 LET D = X - 7 * INT(X/7)
100 IF D <> 0 THEN 120
110 PRINT Y; " ";
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
==={{header|Palo Alto Tiny BASIC}}===
{{trans|GW-BASIC}}
<syntaxhighlight lang="basic">10 REM DAY OF THE WEEK
20 LET M=12,D=25
30 FOR Y=2007 TO 2122
Line 979 ⟶ 996:
220 LET Z=Z+D+(153*M+8)/5
230 LET Z=Z-(Z/7)*7
240 RETURN</syntaxhighlight>
{{out}}
<pre> 2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118</pre>
==={{header|PureBasic}}===
Line 1,057 ⟶ 1,071:
2112
2118</pre>
==={{header|Quite BASIC}}===
The [[#MSX Basic|MSX Basic]] solution works without any changes.
==={{header|Run BASIC}}===
Line 1,627 ⟶ 1,644:
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <
#include <ranges>
#include <iostream>
int main(
std::cout << "Yuletide holidays must be allowed in the following years:\n";
for (int year : std::views::iota(2008, 2121)
| std::views::filter([](auto year) {
if (std::chrono::weekday{
std::chrono::year{year}/std::chrono::December/25}
== std::chrono::Sunday) {
return false;
})) {
std::cout << year << '\n';
}
}</syntaxhighlight>
{{out}}
Line 2,108 ⟶ 2,125:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dayOfTheWeek year month day
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
Line 2,172 ⟶ 2,189:
NthDay += day
# 6. Finally, calculate the day of the week
.
for i = 2008 to 2121
print "Christmas in " & i & " is on Sunday"
.
Line 2,663 ⟶ 2,679:
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Day_of_the_week}}
'''Solution'''
[[File:Fōrmulæ - Day of the week 01.png]]
[[File:Fōrmulæ - Day of the week 02.png]]
=={{header|Frink}}==
Line 2,945 ⟶ 2,963:
=={{header|Java}}==
<syntaxhighlight lang="java">
import static java.util.Calendar.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Line 2,951 ⟶ 2,971:
public class Yuletide{
public static void main(String[] args) {
Calendar calendar;
int count = 1;
for (int year = 2008; year <= 2121; year++) {
calendar = new GregorianCalendar(year, DECEMBER, 25);
if (calendar.get(DAY_OF_WEEK) == SUNDAY) {
if (count != 1)
System.out.print(", ");
System.out.printf("%d", calendar.get(YEAR));
count++;
}
}
}
}
</syntaxhighlight>
{{out}}
<pre>
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
</pre>
=={{header|JavaScript}}==
Line 3,170 ⟶ 3,181:
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072 2078 2089 2095 2101 2107 2112 2118
</syntaxhighlight>
=={{header|Koka}}==
<syntaxhighlight lang="koka">
import std/time/date
import std/time/calendar
import std/time/instant
import std/time/utc
fun main()
for(2008, 2121) fn(year)
val i = instant(year, 12, 25, cal=cal-gregorian)
val dow = (i.days+6)%7 // plus 6 since 2000-01-01 epoch was a Saturday
match dow.weekday
Sun -> println(year.show)
_ -> ()
</syntaxhighlight>
{{out}}
<pre>
2011
2016
2022
2033
2039
2044
2050
2061
2067
2072
2078
2089
2095
2101
2107
2112
2118
</pre>
=={{header|Kotlin}}==
Line 3,554 ⟶ 3,602:
lambda([y], weekday(y, 12, 25) = 'sunday));
/* [2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118] */</syntaxhighlight>
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">import "dateTime"
print "Years between 2008 and 2121 when 25th December falls on Sunday:"
years = []
for year in range(2008, 2121)
date = year + "-12-25"
if dateTime.weekday(date) == 0 then years.push year
end for
print years.join(", ")</syntaxhighlight>
{{out}}
<pre>Years between 2008 and 2121 when 25th December falls on Sunday:
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
</pre>
=={{header|МК-61/52}}==
Line 4,543 ⟶ 4,607:
2112
2118
</pre>
=={{header|PL/M}}==
{{Trans|ALGOL W}}which is{{Trans|Fortran}}
{{works with|8080 PL/M Compiler}} ... under CP/M (or an emulator)
<syntaxhighlight lang="plm">
100H: /* FIND YEARS WHERE CHRISTMAS DAY FALLS ON A SUNDAY */
/* CP/M BDOS SYSTEM CALL AND I/O ROUTINES */
BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GOTO 5; END;
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N ); /* PRINTS A NUMBER IN THE MINIMUN FIELD WIDTH */
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR ( 6 )BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
/* TASK */
/* RETURNS THE DAY OF THE WEEK CORRESPONDING To D/M/Y */
DAY$OF$WEEK: PROCEDURE( D, M, Y )BYTE;
DECLARE ( D, M, Y ) ADDRESS;
DECLARE ( J, K, MM, YY ) ADDRESS;
MM = M;
YY = Y;
IF MM <= 2 THEN DO;
MM = MM + 12;
YY = YY - 1;
END;
J = YY / 100;
K = YY MOD 100;
RETURN ( D + ( ( MM + 1 ) * 26 ) / 10 + K + K / 4 + J / 4 + 5 * J )
MOD 7;
END DAY$OF$WEEK ;
DECLARE ( YEAR, MONTH, DAY, COUNT ) ADDRESS;
CALL PR$STRING( .'25TH OF DECEMBER IS A SUNDAY IN$' );CALL PR$NL;
COUNT = 0;
DO YEAR = 2008 TO 2121;
DAY = DAY$OF$WEEK( 25, 12, YEAR );
IF DAY = 1 THEN DO;
CALL PR$CHAR( ' ' );CALL PR$NUMBER( YEAR );
IF ( COUNT := COUNT + 1 ) MOD 10= 0 THEN CALL PR$NL;
END;
END;
EOF
</syntaxhighlight>
{{out}}
<pre>
25TH OF DECEMBER IS A SUNDAY IN
2011 2016 2022 2033 2039 2044 2050 2061 2067 2072
2078 2089 2095 2101 2107 2112 2118
</pre>
Line 5,037 ⟶ 5,163:
=={{header|RPL}}==
Early RPL versions do not have any date library, so a specific instruction implement Zeller's congruence with a stack-oriented algorithm.
{{works with|
≪ '''IF''' OVER 2 ≤ '''THEN''' 1 - SWAP 12 + SWAP '''END'''
100 MOD LAST / FLOOR
Line 5,043 ⟶ 5,169:
SWAP 1 + 13 * 5 / FLOOR + +
7 MOD 5 + 7 MOD 1 +
≫ '
In 1990, RPL gained some basic functions for calculating the date, but nothing for directly obtaining the day of the week.
{{works with|HP|48}}
≪ { "MON" TUE" "WED" "THU" "FRI" "SAT" "SUN" }
SWAP 0 TSTR 1 3 SUB POS
≫ '<span style="color:blue">WKDAY</span>' STO <span style="color:grey">@ ( dd.mmyyyy → 1..7 )</span>
≪ { } 2008 2121 '''FOR''' year
'''IF''' 25 12 year
≫ EVAL
{{out}}
Line 5,950 ⟶ 6,081:
=={{header|Wren}}==
{{libheader|Wren-date}}
<syntaxhighlight lang="
System.print("Years between 2008 and 2121 when 25th December falls on Sunday:")
|