Day of the week: Difference between revisions

Added MiniScript
(Added MiniScript)
 
(7 intermediate revisions by 6 users not shown)
Line 2,125:
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
procfunc dayOfTheWeek year month day . result .
# Based on Conway's doomsday algorithm
# 1. Calculate the doomsday for the century
Line 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,680 ⟶ 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 3,180 ⟶ 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,564 ⟶ 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,553 ⟶ 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,047 ⟶ 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|Halcyon CalcHP|4.2.728}}
≪ '''IF''' OVER 2 ≤ '''THEN''' 1 - SWAP 12 + SWAP '''END'''
100 MOD LAST / FLOOR
Line 5,053 ⟶ 5,169:
SWAP 1 + 13 * 5 / FLOOR + +
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.
{{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'''
≫ EVAL
{{out}}
Line 5,960 ⟶ 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