Last Friday of each month: Difference between revisions

Added Rebol code
(Nimrod -> Nim)
(Added Rebol code)
Line 1,343:
Fri 28 Dec 2012
</pre>
 
=={{header|REBOL}}==
<lang REBOL>leap-year?: function [year] [to-logic attempt [to-date reduce [29 2 year]]]
 
days-in-feb: function [year] [either leap-year? year [29] [28]]
 
days-in-month: function [month year] [
do pick [31 (days-in-feb year) 31 30 31 30 31 31 30 31 30 31] month
]
 
last-day-of-month: function [month year] [
to-date reduce [year month days-in-month month year]
]
 
last-weekday-of-month: function [weekday month year] [
d: last-day-of-month month year
while [d/weekday != weekday] [d/day: d/day - 1]
d
]
 
last-friday-of-month: function [month year] [last-weekday-of-month 5 month year]
 
year: to-integer input
repeat month 12 [print last-friday-of-month month year]
</lang>
{{out}}
<pre>rebol last-fridays.reb <<< 2012
27-Jan-2012
24-Feb-2012
30-Mar-2012
27-Apr-2012
25-May-2012
29-Jun-2012
27-Jul-2012
31-Aug-2012
28-Sep-2012
26-Oct-2012
30-Nov-2012
28-Dec-2012
</pre>
NB. See "Find the last Sunday of each month" Rosetta for alternative (more succint) solution
 
=={{header|REXX}}==
Anonymous user