Five weekends: Difference between revisions

→‎{{header|J}}: extra credit
m (→‎{{header|Ruby}}: Don't need the uniq.)
(→‎{{header|J}}: extra credit)
Line 51:
 
=={{header|J}}==
<lang j>require 'types/datetime numeric'
find5wkdMonths=: verb define
years=. 1900range + i2{. >: 1900 -~ 2100y
months=. 1 3 5 7 8 10 12
m5w=. (#~ 0 = weekday) >,{years;months;dates31 NB. 5 full weekends iff 31st is Sunday(0)
dates=. 31
m5w=. (#~ 0 = weekday) >,{years;months;dates NB. 5 full weekends iff 31st is Sunday(0)
>'MMM YYYY' fmtDate toDayNo m5w
)</lang>
'''Usage:'''
<lang j> # find5wkdMonths ''1900 2100 NB. number of months found
201
(5&{. , '...' , _5&{.) find5wkdMonths ''1900 2100 NB. First and last 5 months found
Mar 1901
Aug 1902
Line 73 ⟶ 72:
May 2099
Jan 2100
Oct 2100</lang>
# (range -. _ {:"1@". find5wkdMonths) 1900 2100 NB. number of years without 5 weekend months
29</lang>
 
=={{header|Java}}==
892

edits