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


;https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto.27s_methods
BYTE FUNC DayOfWeek(INT y BYTE m,d)	;1<=m<=12, y>1752
  BYTE ARRAY t=[0 3 2 5 0 3 5 1 4 6 2 4]
  BYTE res
 
  IF m<3 THEN
    y==-1
  FI
  res=(y+y/4-y/100+y/400+t(m-1)+d) MOD 7
RETURN (res)
 
BYTE FUNC IsLeapYear(INT y)
  IF y MOD 100=0 THEN
    IF y MOD 400=0 THEN
      RETURN (1)
    ELSE
      RETURN (0)
    FI
  FI
 
  IF y MOD 4=0 THEN
    RETURN (1)
  FI
RETURN (0)
 
INT FUNC GetMaxDay(INT y BYTE m)
  BYTE ARRAY MaxDay=[31 28 31 30 31 30 31 31 30 31 30 31]
 
  IF m=2 AND IsLeapYear(y)=1 THEN
    RETURN (29)
  FI
RETURN (MaxDay(m-1))
 
PROC PrintB2(BYTE x)
  IF x<10 THEN
    Put('0)
  FI
  PrintB(x)
RETURN
 
PROC Main()
  INT MinYear=[1753],MaxYear=[9999],y
  BYTE m,d,last,maxD
 
  DO
    PrintF("Input year in range %I...%I: ",MinYear,MaxYear)
    y=InputI()
  UNTIL y>=MinYear AND y<=MaxYear
  OD
 
  FOR m=1 TO 12
  DO
    last=0
    maxD=GetMaxDay(y,m)
    FOR d=1 TO maxD
    DO
      IF DayOfWeek(y,m,d)=5 THEN
        last=d
      FI
    OD
    PrintI(y) Put('-)
    PrintB2(m) Put('-)
    PrintB2(last) PutE()
  OD
RETURN