## Once In A Blue Moon

### August 31, 2012

The new moon of January 6, 2000 was the 83017th new moon since the start of the julian calendar on January 1, 4700 B.C., so the first new moon of the julian calendar was at day 9.205190498965036. Adding half of 29.530588853 gives us a formula for computing full moons: 23.9704840005 + 29.530588853k. Thus, we can compute the first full moon after a given starting date, then each successive full moon by counting days from that date:

```(define (blue-moons from to)   (define (int x) (inexact->exact (floor x)))   (let* ((delta 29.530588853) (offset 23.9704840005)          (moon (+ offset (* delta (floor (/ from delta))))))     (let loop ((moon moon) (prev 0) (moons (list)))       (if (< to moon) (reverse moons)         (let-values (((y m d) (gregorian (int moon))))           (loop (+ moon delta) m                 (if (= m prev)                     (cons (list m y) moons)                     moons)))))))```

There are thirty-six blue moons in the twenty-first century, including today’s full moon:

```> (blue-moons (julian 2001 1 1) (julian 2100 12 31)) ((10 2001) (7 2004) (5 2007) (12 2009) (8 2012) (7 2015) (1 2018) (3 2018) (10 2020) (8 2023) (5 2026) (12 2028) (9 2031) (6 2034) (1 2037) (3 2037) (10 2039) (7 2042) (4 2045) (12 2047) (9 2050) (6 2053) (1 2056) (3 2056) (10 2058) (7 2061) (4 2064) (12 2066) (8 2069) (5 2072) (1 2075) (3 2075) (10 2077) (7 2080) (5 2083) (12 2085) (8 2088) (6 2091) (1 2094) (3 2094) (10 2096) (8 2099))```

We used the `julian` and `gregorian` functions from the Standard Prelude. You can run the program at http://programmingpraxis.codepad.org/rmEXGyfK.