A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
41
Task/Five-weekends/REXX/five-weekends-1.rexx
Normal file
41
Task/Five-weekends/REXX/five-weekends-1.rexx
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*REXX program finds months with 5 weekends in them (given a date range)*/
|
||||
month. =31 /*month days; Feb. is done later.*/
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*30-day months*/
|
||||
parse arg yStart yStop . /*get the "start" & "stop" years.*/
|
||||
if yStart=='' then yStart=1900 /*if not specified, use default. */
|
||||
if yStop =='' then yStop =2100 /* " " " " " */
|
||||
years=yStop-yStart+1 /*calculate the # of yrs in range*/
|
||||
haps=0 /*num of five weekends happenings*/
|
||||
yr5.=0 /*if a year has any five-weekends*/
|
||||
do y=yStart to yStop /*process the years specified. */
|
||||
do m=1 for 12; wd.=0 /*each month, each yr*/
|
||||
if m==2 then month.2=28+leapyear(y) /*handle #days in Feb*/
|
||||
do d=1 for month.m; dat_=y"-"right(m,2,0)'-'right(d,2,0)
|
||||
?=left(date('W', dat_, "I"), 2); upper ?
|
||||
wd.?=wd.?+1 /*? is 1st 2 chars of weekday*/
|
||||
end /*d*/ /*WD.su=# of Sundays in month*/
|
||||
if wd.su\==5 | wd.fr\==5 | wd.sa\==5 then iterate /*5 W.E.s?*/
|
||||
haps=haps+1 /*bump ctr*/
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
yr5.y=1 /*indicate the year has 5WEs.*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrence"s(haps),
|
||||
'of five-weekend months in year's(years) yStart'──►'yStop; say
|
||||
no5s=0
|
||||
do y=yStart to yStop; if yr5.y then iterate /*skip if OK*/
|
||||
no5s=no5s+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " no5s ' year's(no5s),
|
||||
"that haven't any five─weekend months in year"s(years) yStart'──►'yStop
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────LEAPYEAR subroutine─────────────────*/
|
||||
leapyear: procedure; parse arg y /*year could be: Y, YY, YYY, YYYY*/
|
||||
if length(y)==2 then y=left(right(date(),4),2)y /*adjust for YY year.*/
|
||||
if y//4\==0 then return 0 /* not ÷ by 4? Not a leap year.*/
|
||||
return y//100\==0 | y//400==0 /*apply 100 and 400 year rule. */
|
||||
/*──────────────────────────────────S subroutine────────────────────────*/
|
||||
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*plural*/
|
||||
46
Task/Five-weekends/REXX/five-weekends-2.rexx
Normal file
46
Task/Five-weekends/REXX/five-weekends-2.rexx
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
/*REXX program finds months with 5 weekends in them (given a date range)*/
|
||||
month. =31 /*month days; Feb. is done later.*/
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*30-day months*/
|
||||
@months='January February March April May June July August September October November December'
|
||||
parse arg yStart yStop . /*get the "start" & "stop" years.*/
|
||||
if yStart=='' then yStart=1900 /*if not specified, use default. */
|
||||
if yStop =='' then yStop =2100 /* " " " " " */
|
||||
years=yStop-yStart+1 /*calculate the # of yrs in range*/
|
||||
haps=0 /*num of five weekends happenings*/
|
||||
yr5.=0 /*if a year has any five-weekends*/
|
||||
do y=yStart to yStop /*process the years specified. */
|
||||
do m=1 for 12; wd.=0 /*process each month in each year*/
|
||||
if m==2 then month.2=28+leapyear(y) /*handle #days in Feb.*/
|
||||
do d=1 for month.m
|
||||
?=dow(m,d,y) /*get day-of-week for mm/dd/yyyy.*/
|
||||
wd.?=wd.?+1 /*?: 1=Sun, 2=Mon, ∙∙∙ 7=Sat */
|
||||
end /*d*/
|
||||
if wd.1\==5 | wd.6\==5 | wd.7\==5 then iterate /*5 WEs ? */
|
||||
haps=haps+1 /*bump ctr*/
|
||||
say 'There are five weekends in' y word(@months,m)
|
||||
yr5.y=1 /*indicate this year has 5 WEs. */
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrence"s(haps),
|
||||
'of five-weekend months in year's(years) yStart'──►'yStop; say
|
||||
no5s=0
|
||||
do y=yStart to yStop; if yr5.y then iterate /*skip if OK*/
|
||||
no5s=no5s+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " no5s ' year's(no5s),
|
||||
"that haven't any five─weekend months in year"s(years) yStart'──►'yStop
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────DOW─────────────────────────────────*/
|
||||
dow: procedure; parse arg m,d,y; if m<3 then do; m=m+12; y=y-1; end
|
||||
yL=left(y,2); yr=right(y,2); w=(d+(m+1)*26%10+yr+yr%4+yL%4+5*yL) // 7
|
||||
if w==0 then w=7; return w /*Sunday=1, Monday=2, ... Saturday=7*/
|
||||
/*──────────────────────────────────LEAPYEAR subroutine─────────────────*/
|
||||
leapyear: procedure; parse arg y /*year could be: Y, YY, YYY, YYYY*/
|
||||
if length(y)==2 then y=left(right(date(),4),2)y /*adjust for YY year.*/
|
||||
if y//4\==0 then return 0 /* not ÷ by 4? Not a leap year.*/
|
||||
return y//100\==0 | y//400==0 /*apply 100 and 400 year rule. */
|
||||
/*──────────────────────────────────S subroutine────────────────────────*/
|
||||
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*plural*/
|
||||
55
Task/Five-weekends/REXX/five-weekends-3.rexx
Normal file
55
Task/Five-weekends/REXX/five-weekends-3.rexx
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* REXX ***************************************************************
|
||||
* Short(er) solution focussed at the task's description
|
||||
* Only 7 months can have 5 full weekends
|
||||
* and it's enough to test if the 1st day of the month is a Friday
|
||||
* 30.08.2012 Walter Pachl
|
||||
**********************************************************************/
|
||||
Numeric digits 20
|
||||
nr5fwe=0
|
||||
years_without_5fwe=0
|
||||
mnl='Jan Mar May Jul Aug Oct Dec'
|
||||
ml='1 3 5 7 8 10 12'
|
||||
Do j=1900 to 2100
|
||||
year_has_5fwe=0
|
||||
Do mi=1 To words(ml)
|
||||
m=word(ml,mi)
|
||||
jd=greg2jul(j m 1)
|
||||
IF jd//7=4 Then Do /* 1st m j is a Friday */
|
||||
nr5fwe=nr5fwe+1
|
||||
year_has_5fwe=1
|
||||
If j<=1905 | 2095<=j Then
|
||||
Say word(mnl,mi) j 'has 5 full weekends'
|
||||
End
|
||||
End
|
||||
If j=1905 Then Say '...'
|
||||
if year_has_5fwe=0 Then years_without_5fwe=years_without_5fwe+1
|
||||
End
|
||||
Say ' '
|
||||
Say nr5fwe 'occurrences of 5 full weekends in a month'
|
||||
Say years_without_5fwe 'years without 5 full weekends'
|
||||
exit
|
||||
|
||||
greg2jul: Procedure
|
||||
/***********************************************************************
|
||||
* Converts a Gregorian date to the corresponding Julian day number
|
||||
* 19891101 Walter Pachl REXXified algorithm published in CACM
|
||||
* (Fliegel & vanFlandern, CACM Vol.11 No.10 October 1968)
|
||||
* 19891125 PA copy leapyear test into this to avoid the dependency
|
||||
***********************************************************************/
|
||||
numeric digits 12
|
||||
Parse Arg yy mm d
|
||||
If mm<1 | 12<mm Then Call err 'month ('mm') not within 1 to 12'
|
||||
mdl='31' (28+leapyear(yy)) '31 30 31 30 31 31 30 31 30 31'
|
||||
md=word(mdl,mm)
|
||||
If d<1 | md<d Then Call err 'day ('d') not within 1 to' md
|
||||
/***********************************************************************
|
||||
* The published formula:
|
||||
* res=d-32075+1461*(yy+4800+(mm-14)%12)%4+,
|
||||
* 367*(mm-2-((mm-14)%12)*12)%12-3*((yy+4900+(mm-14)%12)%100)%4
|
||||
***********************************************************************/
|
||||
mma=(mm-14)%12
|
||||
yya=yy+4800+mma
|
||||
result=d-32075+1461*yya%4+367*(mm-2-mma*12)%12-3*((yya+100)%100)%4
|
||||
Return result /* return the result */
|
||||
|
||||
leapyear: Return ( (arg(1)//4=0) & (arg(1)//100<>0) ) | (arg(1)//400=0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue