Last Friday of each month: Difference between revisions

Content added Content deleted
No edit summary
(The K language code given for printing dates of last Fridays of all months a given year.)
Line 1,735: Line 1,735:


Year>
Year>
</pre>

=={{header|K}}==
<lang K>
/ List the dates of last Fridays of each month of
/ a given year
/ lastfridt.k

isleap: {(+/~x!' 4 100 400)!2}
wd: {(_jd x)!7}
dom: (31;28;31;30;31;30;31;31;30;31;30;31)
init: {:[isleap x;dom[1]::29;dom[1]::28]}
wdme: {[m;y]; init y; dt:(10000*y)+(100*m)+dom[m-1];jd::(_jd dt);mewd::(wd dt)}
lfd: {[m;y]; wdme[m;y];:[mewd>3;jd::jd+(4-mewd);jd::jd-(3+mewd)];dt:_dj(jd);yy:$(yr:dt%10000);dd:$(d:dt!100);mm:$(mo:((dt-yr*10000)%100));arr::arr,`$(yy,"-",mm,"-",dd)}
lfd1: {[y];arr::(); m:1; do[12;lfd[m;y];m+:1]}
main: {[y]; lfd1[y]; arr}
</lang>
The output of a session is given below:

{{out}}
<pre>
K Console - Enter \ for help

\l lastfridt

main 2000
`"2000-1-28" `"2000-2-25" `"2000-3-31" `"2000-4-28" `"2000-5-26" `"2000-6-30" `"
2000-7-28" `"2000-8-25" `"2000-9-29" `"2000-10-27" `"2000-11-24" `"2000-12-29"
main 2007
`"2007-1-26" `"2007-2-23" `"2007-3-30" `"2007-4-27" `"2007-5-25" `"2007-6-29" `"
2007-7-27" `"2007-8-31" `"2007-9-28" `"2007-10-26" `"2007-11-30" `"2007-12-28"
main 2018
`"2018-1-26" `"2018-2-23" `"2018-3-30" `"2018-4-27" `"2018-5-25" `"2018-6-29" `"
2018-7-27" `"2018-8-31" `"2018-9-28" `"2018-10-26" `"2018-11-30" `"2018-12-28"
main 2012
`"2012-1-27" `"2012-2-24" `"2012-3-30" `"2012-4-27" `"2012-5-25" `"2012-6-29" `"
2012-7-27" `"2012-8-31" `"2012-9-28" `"2012-10-26" `"2012-11-30" `"2012-12-28"

</pre>
</pre>