2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,19 +1,24 @@
|
|||
The month of October in 2010 has five Fridays, five Saturdays, and five Sundays.
|
||||
|
||||
'''The task'''
|
||||
|
||||
;Task:
|
||||
# Write a program to show all months that have this same characteristic of five full weekends from the year 1900 through 2100 (Gregorian calendar).
|
||||
# Show the ''number'' of months with this property (there should be 201).
|
||||
# Show at least the first and last five dates, in order.
|
||||
|
||||
|
||||
'''Algorithm suggestions'''
|
||||
*Count the number of Fridays, Saturdays, and Sundays in every month.
|
||||
*Find all of the 31-day months that begin on Friday.
|
||||
* Count the number of Fridays, Saturdays, and Sundays in every month.
|
||||
* Find all of the 31-day months that begin on Friday.
|
||||
|
||||
|
||||
'''Extra credit'''
|
||||
|
||||
Count and/or show all of the years which do not have at least one five-weekend month (there should be 29).
|
||||
|
||||
;See also
|
||||
|
||||
;Related tasks
|
||||
* [[Day of the week]]
|
||||
* [[Last Friday of each month]]
|
||||
* [[Find last sunday of each month]]
|
||||
<br><br>
|
||||
|
|
|
|||
100
Task/Five-weekends/360-Assembly/five-weekends.360
Normal file
100
Task/Five-weekends/360-Assembly/five-weekends.360
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
* Five weekends 31/05/2016
|
||||
FIVEWEEK CSECT
|
||||
USING FIVEWEEK,R13 base register
|
||||
B 72(R15) skip savearea
|
||||
DC 17F'0' savearea
|
||||
STM R14,R12,12(R13) prolog
|
||||
ST R13,4(R15) "
|
||||
ST R15,8(R13) "
|
||||
LR R13,R15 "
|
||||
LM R10,R11,=AL8(0) nko=0; nok=0
|
||||
LH R6,Y1 y=y1
|
||||
LOOPY CH R6,Y2 do y=y1 to y2
|
||||
BH ELOOPY
|
||||
MVI YF,X'00' yf=0
|
||||
LA R7,1 im=1
|
||||
LOOPIM C R7,=F'7' do im=1 to 7
|
||||
BH ELOOPIM
|
||||
LR R1,R7 im
|
||||
SLA R1,1 *2 (H)
|
||||
LH R2,ML-2(R1) ml(im)
|
||||
ST R2,M m=ml(im)
|
||||
MVC D,=F'1' d=1
|
||||
L R4,M m
|
||||
C R4,=F'2' if m<=2
|
||||
BH MSUP2
|
||||
L R8,M m
|
||||
LA R8,12(R8) mw=m+12
|
||||
LR R9,R6 y
|
||||
BCTR R9,0 yw=y-1
|
||||
B EMSUP2
|
||||
MSUP2 L R8,M mw=m
|
||||
LR R9,R6 yw=y
|
||||
EMSUP2 LR R4,R9 ym
|
||||
SRDA R4,32 .
|
||||
D R4,=F'100' yw/100
|
||||
ST R5,J j=yw/100
|
||||
ST R4,K k=yw//100
|
||||
LR R4,R8 mw
|
||||
LA R4,1(R4) mw+1
|
||||
MH R4,=H'26' (mw+1)*26
|
||||
SRDA R4,32 .
|
||||
D R4,=F'10' (mw+1)*26/10
|
||||
LR R2,R5 "
|
||||
A R2,D d
|
||||
A R2,K d+k
|
||||
L R3,K k
|
||||
SRA R3,2 k/4
|
||||
AR R2,R3 (mw+1)*26/10+k/4
|
||||
L R3,J j
|
||||
SRA R3,2 j/4
|
||||
AR R2,R3 (mw+1)*26/10+k/4+j/4
|
||||
LA R5,5 5
|
||||
M R4,J 5*j
|
||||
AR R2,R5 (mw+1)*26/10+k/4+j/4
|
||||
SRDA R2,32 .
|
||||
D R2,=F'7' (d+(mw+1)*26/10+k+k/4+j/4+5*j)/7
|
||||
C R2,=F'6' if dow=friday
|
||||
BNE NOFRIDAY
|
||||
XDECO R6,XDEC y
|
||||
MVC PG+0(4),XDEC+8 output y
|
||||
LR R1,R7 im
|
||||
MH R1,=H'3' *3
|
||||
LA R14,MN-3(R1) @mn(im)
|
||||
MVC PG+5(3),0(R14) output mn(im)
|
||||
XPRNT PG,8 print buffer
|
||||
LA R11,1(R11) nok=nok+1
|
||||
MVI YF,X'01' yf=1
|
||||
NOFRIDAY LA R7,1(R7) im=im+1
|
||||
B LOOPIM
|
||||
ELOOPIM L R4,YF yf
|
||||
CLI YF,X'00' if yf=0
|
||||
BNE EYFNE0
|
||||
LA R10,1(R10) nko=nko+1
|
||||
EYFNE0 LA R6,1(R6) y=y+1
|
||||
B LOOPY
|
||||
ELOOPY XDECO R11,XDEC nok
|
||||
MVC PG+0(4),XDEC+8 output nok
|
||||
MVC PG+4(12),=C' occurrences'
|
||||
XPRNT PG,80 print buffer
|
||||
XDECO R10,XDEC nko
|
||||
MVC PG+0(4),XDEC+8 output nko
|
||||
MVC PG+4(33),=C' years with no five weekend month'
|
||||
XPRNT PG,80 print buffer
|
||||
L R13,4(0,R13) epilog
|
||||
LM R14,R12,12(R13) "
|
||||
XR R15,R15 "
|
||||
BR R14 exit
|
||||
Y1 DC H'1900' year start
|
||||
Y2 DC H'2100' year stop
|
||||
ML DC H'1',H'3',H'5',H'7',H'8',H'10',H'12'
|
||||
MN DC C'jan',C'mar',C'may',C'jul',C'aug',C'oct',C'dec'
|
||||
YF DS X year flag
|
||||
M DS F month
|
||||
D DS F day
|
||||
J DS F j=yw/100
|
||||
K DS F j=mod(yw,100)
|
||||
PG DC CL80'....-' buffer
|
||||
XDEC DS CL12 temp for XDECO
|
||||
YREGS
|
||||
END FIVEWEEK
|
||||
145
Task/Five-weekends/AppleScript/five-weekends-2.applescript
Normal file
145
Task/Five-weekends/AppleScript/five-weekends-2.applescript
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
on run
|
||||
|
||||
fiveWeekends(1900, 2100)
|
||||
|
||||
end run
|
||||
|
||||
-- fiveWeekends :: Int -> Int -> Record
|
||||
on fiveWeekends(fromYear, toYear)
|
||||
set lstYears to range(fromYear, toYear)
|
||||
|
||||
-- yearMonthString :: (Int, Int) -> String
|
||||
script yearMonthString
|
||||
on lambda(lstYearMonth)
|
||||
((item 1 of lstYearMonth) as string) & " " & ¬
|
||||
item (item 2 of lstYearMonth) of ¬
|
||||
{"January", "", "March", "", "May", "", ¬
|
||||
"July", "August", "", "October", "", "December"}
|
||||
end lambda
|
||||
end script
|
||||
|
||||
-- addLongMonthsOfYear :: [(Int, Int)] -> [(Int, Int)]
|
||||
script addLongMonthsOfYear
|
||||
on lambda(lstYearMonth, intYear)
|
||||
|
||||
-- yearMonth :: Int -> (Int, Int)
|
||||
script yearMonth
|
||||
on lambda(intMonth)
|
||||
return {intYear, intMonth}
|
||||
end lambda
|
||||
end script
|
||||
|
||||
lstYearMonth & ¬
|
||||
map(yearMonth, my longMonthsStartingFriday(intYear))
|
||||
end lambda
|
||||
end script
|
||||
|
||||
-- leanYear :: Int -> Bool
|
||||
script leanYear
|
||||
on lambda(intYear)
|
||||
0 = length of longMonthsStartingFriday(intYear)
|
||||
end lambda
|
||||
end script
|
||||
|
||||
set lstFullMonths to map(yearMonthString, ¬
|
||||
foldl(addLongMonthsOfYear, {}, lstYears))
|
||||
|
||||
set lstLeanYears to filter(leanYear, lstYears)
|
||||
|
||||
return {{|number|:length of lstFullMonths}, ¬
|
||||
{firstFive:(items 1 thru 5 of lstFullMonths)}, ¬
|
||||
{lastFive:(items -5 thru -1 of lstFullMonths)}, ¬
|
||||
{leanYearCount:length of lstLeanYears}, ¬
|
||||
{leanYears:lstLeanYears}}
|
||||
end fiveWeekends
|
||||
|
||||
|
||||
-- longMonthsStartingFriday :: Int -> [Int]
|
||||
on longMonthsStartingFriday(intYear)
|
||||
|
||||
-- startIsFriday :: Int -> Bool
|
||||
script startIsFriday
|
||||
on lambda(iMonth)
|
||||
weekday of calendarDate(intYear, iMonth, 1) is Friday
|
||||
end lambda
|
||||
end script
|
||||
|
||||
filter(startIsFriday, [1, 3, 5, 7, 8, 10, 12])
|
||||
end longMonthsStartingFriday
|
||||
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
-- GENERIC FUNCTIONS
|
||||
|
||||
-- calendarDate :: Int -> Int -> Int -> Date
|
||||
on calendarDate(intYear, intMonth, intDay)
|
||||
tell (current date)
|
||||
set {its year, its month, its day, its time} to ¬
|
||||
{intYear, intMonth, intDay, 0}
|
||||
return it
|
||||
end tell
|
||||
end calendarDate
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if lambda(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
-- foldl :: (a -> b -> a) -> a -> [b] -> a
|
||||
on foldl(f, startValue, xs)
|
||||
tell mReturn(f)
|
||||
set v to startValue
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to lambda(v, item i of xs, i, xs)
|
||||
end repeat
|
||||
return v
|
||||
end tell
|
||||
end foldl
|
||||
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- range :: Int -> Int -> [Int]
|
||||
on range(m, n)
|
||||
if n < m then
|
||||
set d to -1
|
||||
else
|
||||
set d to 1
|
||||
end if
|
||||
set lst to {}
|
||||
repeat with i from m to n by d
|
||||
set end of lst to i
|
||||
end repeat
|
||||
return lst
|
||||
end range
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{{|number|:201},
|
||||
{firstFive:{"1901 March", "1902 August", "1903 May", "1904 January", "1904 July"}},
|
||||
{lastFive:{"2097 March", "2098 August", "2099 May", "2100 January", "2100 October"}},
|
||||
{leanYearCount:29},
|
||||
{leanYears:{1900, 1906, 1917, 1923, 1928, 1934, 1945, 1951, 1956, 1962, 1973, 1979,
|
||||
1984, 1990, 2001, 2007, 2012, 2018, 2029, 2035, 2040, 2046, 2057, 2063, 2068, 2074,
|
||||
2085, 2091, 2096}}}
|
||||
53
Task/Five-weekends/COBOL/five-weekends.cobol
Normal file
53
Task/Five-weekends/COBOL/five-weekends.cobol
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
program-id. five-we.
|
||||
data division.
|
||||
working-storage section.
|
||||
1 wk binary.
|
||||
2 int-date pic 9(8).
|
||||
2 dow pic 9(4).
|
||||
2 friday pic 9(4) value 5.
|
||||
2 mo-sub pic 9(4).
|
||||
2 months-with-5 pic 9(4) value 0.
|
||||
2 years-no-5 pic 9(4) value 0.
|
||||
2 5-we-flag pic 9(4) value 0.
|
||||
88 5-we-true value 1 when false 0.
|
||||
1 31-day-mos pic 9(14) value 01030507081012.
|
||||
1 31-day-table redefines 31-day-mos.
|
||||
2 mo-no occurs 7 pic 99.
|
||||
1 cal-date.
|
||||
2 yr pic 9(4).
|
||||
2 mo pic 9(2).
|
||||
2 da pic 9(2) value 1.
|
||||
procedure division.
|
||||
perform varying yr from 1900 by 1
|
||||
until yr > 2100
|
||||
set 5-we-true to false
|
||||
perform varying mo-sub from 1 by 1
|
||||
until mo-sub > 7
|
||||
move mo-no (mo-sub) to mo
|
||||
compute int-date = function
|
||||
integer-of-date (function numval (cal-date))
|
||||
compute dow = function mod
|
||||
((int-date - 1) 7) + 1
|
||||
if dow = friday
|
||||
perform output-date
|
||||
add 1 to months-with-5
|
||||
set 5-we-true to true
|
||||
end-if
|
||||
end-perform
|
||||
if not 5-we-true
|
||||
add 1 to years-no-5
|
||||
end-if
|
||||
end-perform
|
||||
perform output-counts
|
||||
stop run
|
||||
.
|
||||
|
||||
output-counts.
|
||||
display "Months with 5 weekends: " months-with-5
|
||||
display "Years without 5 weekends: " years-no-5
|
||||
.
|
||||
|
||||
output-date.
|
||||
display yr "-" mo
|
||||
.
|
||||
end program five-we.
|
||||
46
Task/Five-weekends/Common-Lisp/five-weekends.lisp
Normal file
46
Task/Five-weekends/Common-Lisp/five-weekends.lisp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
;; Given a date, get the day of the week. Adapted from
|
||||
;; http://lispcookbook.github.io/cl-cookbook/dates_and_times.html
|
||||
|
||||
(defun day-of-week (day month year)
|
||||
(nth-value
|
||||
6
|
||||
(decode-universal-time
|
||||
(encode-universal-time 0 0 0 day month year 0)
|
||||
0)))
|
||||
|
||||
(defparameter *long-months* '(1 3 5 7 8 10 12))
|
||||
|
||||
(defun sundayp (day month year)
|
||||
(= (day-of-week day month year) 6))
|
||||
|
||||
(defun ends-on-sunday-p (month year)
|
||||
(sundayp 31 month year))
|
||||
|
||||
;; We use the "long month that ends on Sunday" rule.
|
||||
(defun has-five-weekends-p (month year)
|
||||
(and (member month *long-months*)
|
||||
(ends-on-sunday-p month year)))
|
||||
|
||||
;; For the extra credit problem.
|
||||
(defun has-at-least-one-five-weekend-month-p (year)
|
||||
(let ((flag nil))
|
||||
(loop for month in *long-months* do
|
||||
(if (has-five-weekends-p month year)
|
||||
(setf flag t)))
|
||||
flag))
|
||||
|
||||
(defun solve-it ()
|
||||
(let ((good-months '())
|
||||
(bad-years 0))
|
||||
(loop for year from 1900 to 2100 do
|
||||
;; First form in the PROGN is for the extra credit.
|
||||
(progn (unless (has-at-least-one-five-weekend-month-p year)
|
||||
(incf bad-years))
|
||||
(loop for month in *long-months* do
|
||||
(when (has-five-weekends-p month year)
|
||||
(push (list month year) good-months)))))
|
||||
(let ((len (length good-months)))
|
||||
(format t "~A months have five weekends.~%" len)
|
||||
(format t "First 5 months: ~A~%" (subseq good-months (- len 5) len))
|
||||
(format t "Last 5 months: ~A~%" (subseq good-months 0 5))
|
||||
(format t "Years without a five-weekend month: ~A~%" bad-years))))
|
||||
|
|
@ -3,7 +3,6 @@ import java.util.GregorianCalendar;
|
|||
|
||||
public class FiveFSS {
|
||||
private static boolean[] years = new boolean[201];
|
||||
//dreizig tage habt september...
|
||||
private static int[] month31 = {Calendar.JANUARY, Calendar.MARCH, Calendar.MAY,
|
||||
Calendar.JULY, Calendar.AUGUST, Calendar.OCTOBER, Calendar.DECEMBER};
|
||||
|
||||
|
|
|
|||
57
Task/Five-weekends/JavaScript/five-weekends-3.js
Normal file
57
Task/Five-weekends/JavaScript/five-weekends-3.js
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
|
||||
// longMonthsStartingFriday :: Int -> Int
|
||||
function longMonthsStartingFriday(y) {
|
||||
return [0, 2, 4, 6, 7, 9, 11]
|
||||
.filter(function (m) {
|
||||
return (new Date(Date.UTC(y, m, 1)))
|
||||
.getDay() === 5;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
function range(m, n) {
|
||||
return Array.apply(null, Array(n - m + 1))
|
||||
.map(function (x, i) {
|
||||
return m + i;
|
||||
});
|
||||
}
|
||||
|
||||
var lstNames = [
|
||||
'January', '', 'March', '', 'May', '',
|
||||
'July', 'August', '', 'October', '', 'December'
|
||||
],
|
||||
|
||||
lstYears = range(1900, 2100),
|
||||
|
||||
lstFullMonths = lstYears
|
||||
.reduce(function (a, y) {
|
||||
var strYear = y.toString();
|
||||
|
||||
return a.concat(
|
||||
longMonthsStartingFriday(y)
|
||||
.map(function (m) {
|
||||
return strYear + ' ' + lstNames[m];
|
||||
})
|
||||
);
|
||||
}, []),
|
||||
|
||||
lstLeanYears = lstYears
|
||||
.filter(function (y) {
|
||||
return longMonthsStartingFriday(y)
|
||||
.length === 0;
|
||||
});
|
||||
|
||||
return JSON.stringify({
|
||||
number: lstFullMonths.length,
|
||||
firstFive: lstFullMonths.slice(0, 5),
|
||||
lastFive: lstFullMonths.slice(-5),
|
||||
leanYearCount: lstLeanYears.length
|
||||
},
|
||||
null, 2
|
||||
);
|
||||
|
||||
})();
|
||||
30
Task/Five-weekends/Lua/five-weekends.lua
Normal file
30
Task/Five-weekends/Lua/five-weekends.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
local months={"JAN","MAR","MAY","JUL","AUG","OCT","DEC"}
|
||||
local daysPerMonth={31+28,31+30,31+30,31,31+30,31+30,0}
|
||||
|
||||
function find5weMonths(year)
|
||||
local list={}
|
||||
local startday=((year-1)*365+math.floor((year-1)/4)-math.floor((year-1)/100)+math.floor((year-1)/400))%7
|
||||
|
||||
for i,v in ipairs(daysPerMonth) do
|
||||
if startday==4 then list[#list+1]=months[i] end
|
||||
if i==1 and year%4==0 and year%100~=0 or year%400==0 then
|
||||
startday=startday+1
|
||||
end
|
||||
startday=(startday+v)%7
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
local cnt_months=0
|
||||
local cnt_no5we=0
|
||||
|
||||
for y=1900,2100 do
|
||||
local list=find5weMonths(y)
|
||||
cnt_months=cnt_months+#list
|
||||
if #list==0 then
|
||||
cnt_no5we=cnt_no5we+1
|
||||
end
|
||||
print(y.." "..#list..": "..table.concat(list,", "))
|
||||
end
|
||||
print("Months with 5 weekends: ",cnt_months)
|
||||
print("Years without 5 weekends in the same month:",cnt_no5we)
|
||||
77
Task/Five-weekends/NewLISP/five-weekends.newlisp
Normal file
77
Task/Five-weekends/NewLISP/five-weekends.newlisp
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/local/bin/newlisp
|
||||
|
||||
(context 'KR)
|
||||
|
||||
(define (Kraitchik year month day)
|
||||
; See https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Kraitchik.27s_variation
|
||||
; Function adapted for specific task (not for general usage).
|
||||
(if (or (= 1 month) (= 2 month))
|
||||
(dec year)
|
||||
)
|
||||
;- - - -
|
||||
(setf m-table '(_ 1 4 3 6 1 4 6 2 5 0 3 5)) ; - - - First element of list is dummy!
|
||||
(setf m (m-table month))
|
||||
;- - - -
|
||||
(setf c-table '(0 5 3 1))
|
||||
(setf century%4 (mod (int (slice (string year) 0 2)) 4))
|
||||
(setf c (c-table century%4))
|
||||
;- - - -
|
||||
(setf yy* (slice (string year) -2))
|
||||
(if (= "0" (yy* 0))
|
||||
(setf yy* (yy* 1))
|
||||
)
|
||||
(setf yy (int yy*))
|
||||
(setf y (mod (+ (/ yy 4) yy) 7))
|
||||
;- - - -
|
||||
(setf dow-table '(6 0 1 2 3 4 5))
|
||||
(dow-table (mod (+ day m c y) 7))
|
||||
)
|
||||
|
||||
(context 'MAIN)
|
||||
|
||||
(setf Fives 0)
|
||||
(setf NotFives 0)
|
||||
(setf Report '())
|
||||
(setf months-table '((1 "Jan") (3 "Mar") (5 "May") (7 "Jul") (8 "Aug") (10 "Oct") (12 "Dec")))
|
||||
|
||||
(for (y 1900 2100)
|
||||
(setf FivesFound 0)
|
||||
(setf Names "")
|
||||
(dolist (m '(1 3 5 7 8 10 12))
|
||||
(setf Dow (KR:Kraitchik y m 1))
|
||||
(if (= 5 Dow)
|
||||
(begin
|
||||
(++ FivesFound)
|
||||
(setf Names (string Names " " (lookup m months-table)))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
(if (zero? FivesFound)
|
||||
(++ NotFives)
|
||||
(begin
|
||||
(setf Report (append Report (list (list y FivesFound (string "(" Names " )")))))
|
||||
(setf Fives (+ Fives FivesFound))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
;- - - - Display all report data
|
||||
;(dolist (x Report)
|
||||
; (println (x 0) ": " (x 1) " " (x 2))
|
||||
;)
|
||||
|
||||
|
||||
;- - - - Display only first five and last five records
|
||||
(dolist (x (slice Report 0 5))
|
||||
(println (x 0) ": " (x 1) " " (x 2))
|
||||
)
|
||||
(println "...")
|
||||
(dolist (x (slice Report -5))
|
||||
(println (x 0) ": " (x 1) " " (x 2))
|
||||
)
|
||||
|
||||
(println "\nTotal months with five weekends: " Fives)
|
||||
(println "Years with no five weekends months: " NotFives)
|
||||
(exit)
|
||||
|
|
@ -1,38 +1,31 @@
|
|||
/*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*/
|
||||
!.=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, each year. */
|
||||
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)
|
||||
/*REXX program finds months that contain five weekends (given a date range). */
|
||||
month. =31; month.2=0 /*month days; February is skipped. */
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*all the months with thirty-days. */
|
||||
parse arg yStart yStop . /*get the "start" and "stop" years.*/
|
||||
if yStart=='' | yStart=="," then yStart= 1900 /*Not specified? Then use the default.*/
|
||||
if yStop =='' | yStop =="," then yStop = 2100 /* " " " " " " */
|
||||
years=yStop - yStart + 1 /*calculate the number of yrs in range.*/
|
||||
haps=0 /*number of five weekends happenings. */
|
||||
!.=0; @5w= 'five-weekend months' /*flag 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 and also each year*/
|
||||
do d=1 for month.m; dat_= y"-"right(m,2,0)'-'right(d,2,0)
|
||||
parse upper value date('W', dat_, "I") with ? 3
|
||||
wd.?=wd.?+1 /*? is the 1st 2 chars of weekday*/
|
||||
end /*d*/ /*WD.su = # of Sundays in a month*/
|
||||
if wd.su\==5 | wd.fr\==5 | wd.sa\==5 then iterate /*5 W.E.s?*/
|
||||
wd.?=wd.?+1 /*? is the first two chars of weekday.*/
|
||||
end /*d*/ /*WD.su = number of Sundays in a month.*/
|
||||
if wd.su\==5 | wd.fr\==5 | wd.sa\==5 then iterate /*five weekends ?*/
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
haps=haps+1; !.y=1 /*bump ctr; indicate yr has 5 WEs*/
|
||||
haps=haps+1; !.y=1 /*bump counter; indicate yr has 5 WE's.*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrence"s(haps) 'of five-weekend months in year's(years) yStart'──►'yStop
|
||||
say "There were " haps ' occurrence's(haps) "of" @5w 'in year's(years) yStart"──►"yStop
|
||||
say; #=0
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK.*/
|
||||
#=#+1; say 'Year ' y " doesn't have any" @5wem'.'
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " # ' year's(#) "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*/
|
||||
say "There are " # ' year's(#) "that haven't any" @5w 'in year's(years) yStart'──►'yStop
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
|
||||
|
|
|
|||
|
|
@ -1,43 +1,37 @@
|
|||
/*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*/
|
||||
/*REXX program finds months that contain five weekends (given a date range). */
|
||||
month. =31; month,2=0 /*month days; February is skipped. */
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*all the months with thirty-days. */
|
||||
@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*/
|
||||
!.=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.*/
|
||||
parse arg yStart yStop . /*get the "start" and "stop" years.*/
|
||||
if yStart=='' | yStart=="," then yStart= 1900 /*Not specified? Then use the default.*/
|
||||
if yStop =='' | yStop =="," then yStop = 2100 /* " " " " " " */
|
||||
years=yStop - yStart + 1 /*calculate the number of yrs in range.*/
|
||||
haps=0 /*number of five weekends happenings. */
|
||||
!.=0; @5w= 'five-weekend months' /*flag 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 and also each year*/
|
||||
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 */
|
||||
?=dow(m,d,y) /*get the day-of-week for mm/dd/yyyy*/
|
||||
wd.?=wd.?+1 /*?: 1=Sun, 2=Mon, 3=Tue ∙∙∙ 7=Sat.*/
|
||||
end /*d*/
|
||||
if wd.1\==5 | wd.6\==5 | wd.7\==5 then iterate /*5 WEs ? */
|
||||
say 'There are five weekends in' y word(@months,m)
|
||||
haps=haps+1; !.y=1 /*bump ctr; indicate yr has 5 WEs*/
|
||||
end /*m*/
|
||||
if wd.1\==5 | wd.6\==5 | wd.7\==5 then iterate /*not a weekend ? */
|
||||
say 'There are five weekends in' y word(@months, m)
|
||||
haps=haps+1; !.y=1 /*bump counter; indicate yr has 5 WE's.*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrence"s(haps) 'of five-weekend months in year's(years) yStart'──►'yStop
|
||||
say 'There were ' haps " occurrence"s(haps) 'of' @5w "in year"s(years) yStart'──►'yStop
|
||||
#=0; say
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK*/
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK.*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " # ' year's(#) "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*/
|
||||
say "There are " # ' year's(#) "that haven't any" @5w 'in year's(years) yStart'──►'yStop
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
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 */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*pluralizer.*/
|
||||
|
|
|
|||
|
|
@ -1,28 +1,30 @@
|
|||
/*REXX program finds months with 5 weekends in them (given a date range)*/
|
||||
month. =31 /*month days; Feb. is skipped. */
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*30-day months*/
|
||||
yStart=1900; yStop=2100 /*define start and stop years. */
|
||||
haps=0 /*num of five weekends happenings*/
|
||||
!.=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 except Feb, each yr.*/
|
||||
if m==2 then iterate /*if month is February, skip it. */
|
||||
do d=1 for month.m; dat_=y"-"right(m,2,0)'-'right(d,2,0)
|
||||
/*REXX program finds months that contain five weekends (given a date range). */
|
||||
month. =31; month.2=0 /*month days; February is skipped. */
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*all the months with thirty-days. */
|
||||
parse arg yStart yStop . /*get the "start" and "stop" years.*/
|
||||
if yStart=='' | yStart=="," then yStart= 1900 /*Not specified? Then use the default.*/
|
||||
if yStop =='' | yStop =="," then yStop = 2100 /* " " " " " " */
|
||||
years=yStop - yStart + 1 /*calculate the number of yrs in range.*/
|
||||
haps=0 /*number of five weekends happenings. */
|
||||
!.=0; @5w= 'five-weekend months' /*flag 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 and also each year*/
|
||||
do d=1 for month.m; dat_= y"-"right(m, 2, 0)'-'right(d, 2, 0)
|
||||
parse upper value date('W', dat_, "I") with ? 3
|
||||
wd.?=wd.?+1 /*? is 1st 2 chars of tge weekday*/
|
||||
end /*d*/ /*WD.su=# of Sundays in the month*/
|
||||
if wd.su\==5 | wd.fr\==5 | wd.sa\==5 then iterate /*5 W.E.s?*/
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
haps=haps+1; !.y=1 /*bump ctr; indicate yr has 5 WEs*/
|
||||
wd.?=wd.?+1 /*?: 1=Sun, 2=Mon, 3=Tue ∙∙∙ 7=Sat.*/
|
||||
end /*d*/ /*WD.su=number of Sundays in the month.*/
|
||||
if wd.su\==5 | wd.fr\==5 | wd.sa\==5 then iterate /*is this a weekend ? */
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
haps=haps+1; !.y=1 /*bump counter; indicate yr has 5 WE's.*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrences of five-weekend months in years" yStart'──►'yStop; say
|
||||
#=0
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say 'There were ' haps " occurrence"s(haps) 'of' @5w "in year"s(years) yStart'──►'yStop
|
||||
#=0; say
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK.*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " # " years that haven't any five─weekend months in years" yStart'──►'yStop
|
||||
/*stick a fork in it, we're done.*/
|
||||
say "There are " # ' year's(#) "that haven't any" @5w 'in year's(years) yStart'──►'yStop
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -1,23 +1,27 @@
|
|||
/*REXX program finds months with 5 weekends in them (given a date range)*/
|
||||
month.=31; yStart=1900; yStop=2100 /*month days; range of years. */
|
||||
month.2=0; month.4=0; month.6=0; month.9=0; month.11=0 /*¬31 day months*/
|
||||
haps=0 /*num of five weekends happenings*/
|
||||
!.=0 /*if a year has any five-weekends*/
|
||||
do y=yStart to yStop /*process the years specified. */
|
||||
do m=1 for 12; if month.m==0 then iterate /*test 31-day mons*/
|
||||
dat_=y"-"right(m,2,0)'-01' /*get date in the proper format. */
|
||||
if left(date('W',dat_,"I"),2)\=='Fr' then iterate /*Friday?*/
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
haps=haps+1; !.y=1 /*bump ctr; indicate yr has 5 WEs*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
/*REXX program finds months that contain five weekends (given a date range). */
|
||||
month. =31 /*days in "all" the months. */
|
||||
month.2=0; month.4=0; month.6=0; month.9=0; month.11=0 /*not 31 day months.*/
|
||||
month.4=30; month.6=30; month.9=30; month.11=30 /*all the months with thirty-days. */
|
||||
parse arg yStart yStop . /*get the "start" and "stop" years.*/
|
||||
if yStart=='' | yStart=="," then yStart= 1900 /*Not specified? Then use the default.*/
|
||||
if yStop =='' | yStop =="," then yStop = 2100 /* " " " " " " */
|
||||
years=yStop - yStart + 1 /*calculate the number of yrs in range.*/
|
||||
haps=0 /*number of five weekends happenings. */
|
||||
!.=0; @5w= 'five-weekend months' /*flag if a year has any five-weekends.*/
|
||||
do y=yStart to yStop /*process the years specified. */
|
||||
do m=1 for 12; if month.m==0 then iterate /*only test 31-day months.*/
|
||||
dat_= y"-"right(m,2,0)'-01' /*get the date in the desired format. */
|
||||
if left(date('W',dat_,"I"),2)\=='Fr' then iterate /*isn't not a Friday? */
|
||||
say 'There are five weekends in' y date('M', dat_, "I")
|
||||
haps=haps+1; !.y=1 /*bump counter; indicate yr has 5 WE's.*/
|
||||
end /*m*/
|
||||
end /*y*/
|
||||
say
|
||||
say 'There were ' haps " occurrences of five-weekend months in years" yStart'──►'yStop; say
|
||||
#=0
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say 'There were ' haps " occurrence"s(haps) 'of' @5w "in year"s(years) yStart'──►'yStop
|
||||
#=0; say
|
||||
do y=yStart to yStop; if !.y then iterate /*skip if OK.*/
|
||||
#=#+1
|
||||
say 'Year ' y " doesn't have any five-weekend months."
|
||||
end /*y*/
|
||||
say
|
||||
say "There are " # " years that haven't any five─weekend months in years" yStart'──►'yStop
|
||||
/*stick a fork in it, we're done.*/
|
||||
say "There are " # ' year's(#) "that haven't any" @5w 'in year's(years) yStart'──►'yStop
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue