[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/LmOgrg98    [ raw code | output | fork ]

programmingpraxis - Scheme, pasted on Feb 23:
(define (easter year)
  (let* ((a (modulo year 19))
         (b (quotient year 100))
         (c (modulo year 100))
         (d (quotient b 4))
         (e (modulo b 4))
         (f (quotient (+ b 8) 25))
         (g (quotient (+ (- b f) 1) 3))
         (h (modulo (- (+ (* 19 a) b 15) d g) 30))
         (i (quotient c 4))
         (k (modulo c 4))
         (l (modulo (- (+ 32 (* 2 e) (* 2 i)) h k) 7))
         (m (quotient (+ a (* 11 h) (* 22 l)) 451))
         (month (quotient (- (+ h l 114) (* 7 m)) 31))
         (day (+ (modulo (- (+ h l 114) (* 7 m)) 31) 1)))
    (values month day)))

(define (julian year month day)
  (let* ((a (quotient (- 14 month) 12))
         (y (+ year 4800 (- a)))
         (m (+ month (* 12 a) -3)))
    (+ day
       (quotient (+ (* 153 m) 2) 5)
       (* 365 y)
       (quotient y 4)
       (- (quotient y 100))
       (quotient y 400)
       (- 32045))))

(define (gregorian julian)
  (let* ((j (+ julian 32044))
         (g (quotient j 146097))
         (dg (modulo j 146097))
         (c (quotient (* (+ (quotient dg 36524) 1) 3) 4))
         (dc (- dg (* c 36524)))
         (b (quotient dc 1461))
         (db (modulo dc 1461))
         (a (quotient (* (+ (quotient db 365) 1) 3) 4))
         (da (- db (* a 365)))
         (y (+ (* g 400) (* c 100) (* b 4) a))
         (m (- (quotient (+ (* da 5) 308) 153) 2))
         (d (+ da (- (quotient (* (+ m 4) 153) 5)) 122))
         (year (+ y (- 4800) (quotient (+ m 2) 12)))
         (month (+ (modulo (+ m 2) 12) 1))
         (day (+ d 1)))
    (values year month day)))

(define (easter-plus year days)
  (call-with-values
    (lambda () (easter year))
    (lambda (month day)
      (gregorian
        (+ (julian year month day) days)))))

(call-with-values
  (lambda () (easter-plus 1989 -47))
  (lambda (year month day)
    (display year) (display " ")
    (display month) (display " ")
    (display day) (newline)))

(call-with-values
  (lambda () (easter-plus 2049 -47))
  (lambda (year month day)
    (display year) (display " ")
    (display month) (display " ")
    (display day) (newline)))


Output:
1
2
1989 2 7
2049 3 2


Create a new paste based on this one


Comments: