Jump to content

Last Friday of each month: Difference between revisions

Minor change in the program to print each date on a separate line
(The K language code given for printing dates of last Fridays of all months a given year.)
(Minor change in the program to print each date on a separate line)
Line 1,748:
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,"-",(2$mm),"-",(2$dd))}
lfd1: {[y];arr::(); m:1; do[12;lfd[m;y];m+:1]}
main: {[y]; lfd1[y];`0: ,"Dates of last Fridays of ",($y);12 10#arr}
 
</lang>
The output of a session is given below:
Line 1,759 ⟶ 1,760:
 
\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
Dates of last Fridays of 2012
`"2012-1-27" `"2012-2-24" `"2012-3-30" `"2012-4-27" `"2012-5-25" `"2012-6-29" `"
("2012- 1-27"
2012-7-27" `"2012-8-31" `"2012-9-28" `"2012-10-26" `"2012-11-30" `"2012-12-28"
"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>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.