Task

Write a program or a script that returns the date of the last Fridays of each month of a given year.

The year may be given through any simple input method in your language (command line, std in, etc).



Example of an expected output:

./last_fridays 2012
2012-01-27
2012-02-24
2012-03-30
2012-04-27
2012-05-25
2012-06-29
2012-07-27
2012-08-31
2012-09-28
2012-10-26
2012-11-30
2012-12-28



Related tasks
 Five weekends
 Day of the week
 Find the last Sunday of each month


\\ Normalized Julian Day Number from date
njd(D) =
{
  my (m = D[2], y = D[1]);
 
  if (D[2] > 2, m++, y--; m += 13);
 
  (1461 * y) \ 4 + (306001 * m) \ 10000 + D[3] - 694024 + 2 - y \ 100 + y \ 400
}
 
\\ Date from Normalized Julian Day Number
njdate(J) =
{
  my (a = J + 2415019, b = (4 * a - 7468865) \ 146097, c, d, m, y);
 
  a += 1 + b - b \ 4 + 1524;
  b = (20 * a - 2442) \ 7305;
  c = (1461 * b) \ 4;
  d = ((a - c) * 10000) \ 306001;
  m = d - 1 - 12 * (d > 13);
  y = b - 4715 - (m > 2);
  d = a - c - (306001 * d) \ 10000;
 
  [y, m, d]
}
 
for (m=1, 12, a=njd([2012,m+1,0]); print(njdate(a-(a+1)%7)))