Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 months = %w[march april may june july august september october november december january february]



def zeller(year, month, day)

    months = %w[march april may june july august september october november december january february]

    weekdays = %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]

    k = day

    m = months.index(month.downcase) + 1

    y = (m <= 10) ? year : year-1

    d = y % 100

    c = y / 100

    f = (k + (((13*m) - 1) / 5).floor + d + (d/4).floor + (c/4).floor - (2*c)) % 7

    weekdays[f]

end



1900.upto(2300) do |y|

  if zeller(y, "august", 1) == "Friday"

    # this august has five fridays, sats, and suns.

    # loop through all months to see which ones ALSO had five fri/sat/sun this year

    months.each do |month|

      if zeller(y,month,1) == "Friday"

        puts "#{month} had fivefrisatsuns in #{y}!"

      end

    end

  end

end