Day of the week: Difference between revisions

Added MiniScript
(Day of the week in Chipmunk Basic)
(Added MiniScript)
 
(14 intermediate revisions by 11 users not shown)
Line 943:
 
==={{header|Minimal BASIC}}===
{{works with|IS-BASIC}}
<syntaxhighlight lang="gwbasic">
<syntaxhighlight lang="gwbasic">10 REM Find years with Sunday Christmas
20 LET F = 2008
30 LET T = 2121
Line 957:
120 NEXT Y
130 PRINT
140 END</syntaxhighlight>
 
</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
40 GOSUB 200
50 IF Z=0 PRINT Y," ",
60 NEXT Y
70 PRINT
80 STOP
170 REM CALCULATE DAY OF WEEK Z GIVEN
180 REM YEAR Y, MONTH M, AND DAY D
190 REM SUNDAY = 0, SATURDAY = 6
200 IF M<3 LET Y=Y-1,M=M+12
210 LET Z=Y+Y/4-Y/100+Y/400
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,031 ⟶ 1,071:
2112
2118</pre>
 
==={{header|Quite BASIC}}===
The [[#MSX Basic|MSX Basic]] solution works without any changes.
 
==={{header|Run BASIC}}===
Line 1,601 ⟶ 1,644:
 
=={{header|C++}}==
<syntaxhighlight lang="cpp">#include <boost/date_time/gregorian/gregorian.hppchrono>
#include <ranges>
#include <iostream>
 
int main( ) {
std::cout << "Yuletide holidays must be allowed in the following years:\n";
using namespace boost::gregorian ;
for (int year : std::views::iota(2008, 2121)
 
| std::views::filter([](auto year) {
std::cout
if (std::chrono::weekday{
<< "Yuletide holidays must be allowed in the following years:\n" ;
std::chrono::year{year}/std::chrono::December/25}
for ( int i = 2008 ; i < 2121 ; i++ ) {
== std::chrono::Sunday) {
greg_year gy = i ;
date d ( gy, Dec , 25 ) return true;
if ( d.day_of_week( ) == Sunday ) { }
return false;
std::cout << i << std::endl ;
})) {
std::cout << year << '\n';
}
}
std::cout << "\n" ;
return 0 ;
}</syntaxhighlight>
{{out}}
Line 2,082 ⟶ 2,125:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func dayOfTheWeek year month day . result .
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
Line 2,146 ⟶ 2,189:
NthDay += day
# 6. Finally, calculate the day of the week
result =return (januaryOne + NthDay - 1) mod 7
.
for i = 2008 to 2121
callif dayOfTheWeek i 12 25 result= 0
if result = 0
print "Christmas in " & i & " is on Sunday"
.
Line 2,637 ⟶ 2,679:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Day_of_the_week}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Day of the week 01.png]]
In '''[https://formulae.org/?example=Day_of_the_week this]''' page you can see the program(s) related to this task and their results.
 
[[File:Fōrmulæ - Day of the week 02.png]]
 
=={{header|Frink}}==
Line 2,919 ⟶ 2,963:
 
=={{header|Java}}==
<syntaxhighlight lang="java">import java.util.Calendar;
import static java.util.Calendar.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
Line 2,925 ⟶ 2,971:
public class Yuletide{
public static void main(String[] args) {
Calendar calendar;
for(int i = 2008;i<=2121;i++){
int count = 1;
Calendar cal = new GregorianCalendar(i, Calendar.DECEMBER,
for (int year = 2008; year <= 2121; year++) {
25);
calendar = new GregorianCalendar(year, DECEMBER, 25);
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
if (calendar.get(DAY_OF_WEEK) == SUNDAY) {
System.out.println(cal.getTime());
if (count != 1)
}
System.out.print(", ");
}
System.out.printf("%d", calendar.get(YEAR));
count++;
}
}
}
}
}</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>
<pre>Sun Dec 25 00:00:00 CST 2011
2011, 2016, 2022, 2033, 2039, 2044, 2050, 2061, 2067, 2072, 2078, 2089, 2095, 2101, 2107, 2112, 2118
Sun Dec 25 00:00:00 CST 2016
</pre>
Sun Dec 25 00:00:00 CST 2022
Sun Dec 25 00:00:00 CST 2033
Sun Dec 25 00:00:00 CST 2039
Sun Dec 25 00:00:00 CST 2044
Sun Dec 25 00:00:00 CST 2050
Sun Dec 25 00:00:00 CST 2061
Sun Dec 25 00:00:00 CST 2067
Sun Dec 25 00:00:00 CST 2072
Sun Dec 25 00:00:00 CST 2078
Sun Dec 25 00:00:00 CST 2089
Sun Dec 25 00:00:00 CST 2095
Sun Dec 25 00:00:00 CST 2101
Sun Dec 25 00:00:00 CST 2107
Sun Dec 25 00:00:00 CST 2112
Sun Dec 25 00:00:00 CST 2118</pre>
 
=={{header|JavaScript}}==
Line 3,144 ⟶ 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,528 ⟶ 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,517 ⟶ 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,010 ⟶ 5,162:
 
=={{header|RPL}}==
Early RPL doesversions do not have any date library, so a specific instruction implementsimplement Zeller's congruence with a stack-oriented algorithm.
{{works with|Halcyon CalcHP|4.2.728}}
'''IF''' OVER 2 ≤ '''THEN''' 1 - SWAP 12 + SWAP '''END'''
100 MOD LAST / IP FLOOR
DUP 4 / IPFLOOR SWAP DUP + - SWAP DUP 4 / IPFLOOR + +
SWAP 1 + 13 * 5 / IPFLOOR + +
7 MOD 5 + 7 MOD 1 +
≫ '<span style="color:blue">WKDAY</span>' STO
In 1990, RPL gained some basic functions for calculating the date, but nothing for directly obtaining the day of the week.
'WKDAY' STO
{{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 <span style="color:blue">WKDAY</span> 7 == '''THEN''' year + '''END NEXT'''
2008 2121 FOR year
≫ EVAL
IF 25 12 year WKDAY 7 == THEN year + END
NEXT
EVAL
{{out}}
<pre>
Line 5,928 ⟶ 6,081:
=={{header|Wren}}==
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
 
System.print("Years between 2008 and 2121 when 25th December falls on Sunday:")
9,476

edits