[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]
Article: 12279 of comp.protocols.kermit.misc
From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
Newsgroups: comp.protocols.kermit.misc
Subject: Case Study #22: More fun with dates
Date:Tue Mar 13 16:52:59 EST 2001
Organization: Columbia University
This month's Scientific American (March 2001, p.80) includes an article "Easter as a Quasicrystal" by Ian Stewart, in which the calculation of the date of Easter is explained (and then graphed and compared to a crystalline lattice). A ten-step algorithm is given for calculating the Gregorian date of Easter in any given year that is "easy to program on a computer"). Here's an illustration of how to do it in C-Kermit 8.0, using its new LISP-like S-expression feature:
#!/usr/local/bin/kermit + dcl \&m[] = Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec if ( not def \%1 || not numeric \%1 ) exit 1 Usage: \%0 year if ( < \%1 1900 || > \%1 2199 ) exit 1 "\0: 1900 <= Year < 2100" (setq x \%1) (setq a (mod x 19) b (truncate (/ x 100)) c (mod x 100)) (setq d (truncate (/ b 4)) e (mod b 4)) (setq g (truncate (/ (+ (* 8 b) 13) 25))) (setq h (mod (+ (* a 19) b (- d) (- g) 15) 30)) (setq m (truncate (/ (+ a (* h 11)) 319))) (setq j (truncate (/ c 4)) k (truncate (mod c 4))) (setq l (truncate (mod (+ (* 2 e) (* 2 j) m (- k) (- h) 32) 7))) (setq n (truncate (/ (+ h (- m) l 90) 25))) (setq p (truncate (mod (+ h (- m) l n 19) 32))) echo \fday(\m(x)\flpad(\m(n),2,0)\flpad(\m(p),2,0)) \m(p) \&m[n] \m(x) exit
See the article for an explanation of the algorithm and see:
http://www.columbia.edu/kermit/ckermit3.html#x9
for an explanation of S-Expressions. Note that the algorithm requires all arithmetic to be integer, not floating-point, hence the many TRUNCATE expressions (since S-Expressions never discard fractional parts).
In UNIX, clip the program, left-justify at least the first line and change it to point to your C-Kermit 8.0 binary, save it as "easter", then "chmod +x easter", and then you can type:
easter 2001
(or any other year between 1900 and 2099) to find out the date for Easter in that year (years outside that range require adjustment of the algorithm). On other platforms, type "take easter 2001" (or other year) at the Kermit prompt.
Exercises:
- Frank
[ Top ] [ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]
Kermit Case Study 22 / Columbia University / kermit@kermitproject.org / 14 Mar 2001