RosettaCodeData/Task/Five-weekends/XPL0/five-weekends.xpl0
2015-02-20 00:35:01 -05:00

38 lines
1.6 KiB
Text

include c:\cxpl\codes; \intrinsic 'code' declarations
func WeekDay(Year, Month, Day); \Return day of week (0=Sat 1=Sun..6=Fri)
int Year, Month, Day;
[if Month<=2 then [Month:= Month+12; Year:= Year-1];
return rem((Day + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400) / 7);
]; \WeekDay
int MonthTbl, Year, I, C;
[MonthTbl:= [1, 3, 5, 7, 8, 10, 12]; \months with 31 days
C:= 0;
for Year:= 1900 to 2100 do
for I:= 0 to 6 do \for all the 31-day months...
if WeekDay(Year, MonthTbl(I), 1) = 6 then \first of month is a Friday
[C:= C+1; \count this year
if C<=5 or C>201-5 then \show first 5 and last 5 years
[IntOut(0, Year); ChOut(0, ^ );
IntOut(0, MonthTbl(I)); CrLf(0);
];
];
IntOut(0, C); CrLf(0); \show number of years
\Count and show all years that don't have any 5-weekend months
C:= 0;
for Year:= 1900 to 2100 do
[for I:= 0 to 6 do \for all the 31-day months...
if WeekDay(Year, MonthTbl(I), 1) = 6 \Friday\ then
I:= 10; \bail out of 'for' loop
if I<10 then \'for' loop completed
[if (C&$F) = 0 then CrLf(0); \(format 16 years per line)
C:= C+1; \ without finding a 5-weekend
IntOut(0, Year); ChOut(0, ^ ); \ so show the year
];
];
CrLf(0); IntOut(0, C); CrLf(0); \show number of years
]