-
-
Notifications
You must be signed in to change notification settings - Fork 360
Computus Common Lisp Implementation #724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
berquist
merged 3 commits into
algorithm-archivists:master
from
Trashtalk217:computus-lisp
Jul 14, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
;;;; Gauss's Easter algorithm implementation | ||
|
||
(defun computus (year &optional (servois nil)) | ||
"Calculates the day of Easter for a given year and optionally its Servois number" | ||
(let* | ||
((a (mod year 19)) ; year's position on the 19 year metonic cycle | ||
(k (floor year 100)) ; century index | ||
(p (floor (+ 13 (* 8 k)) 25)) ; shift of metonic cycle, add a day offset every 300 years | ||
(q (floor k 4)) ; correction for non-observed leap days | ||
(m (mod (+ 15 (- p) k (- q)) 30)) ; correction to starting point of calculation each century | ||
(d (mod (+ (* 19 a) m) 30)) ; number of days from March 21st until the full moon | ||
(n (mod (+ 4 k (- q)) 7)) ; century-based offset in weekly calculation | ||
(b (mod year 4)) ; correction for leap days | ||
(c (mod year 7)) ; also a correction for leap days | ||
;; days from d to next Sunday | ||
(e (mod (+ (* 2 b) (* 4 c) (* 6 d) n) 7))) | ||
;; historical corrections for April 26 and 25 | ||
(when (or (and (eql d 29) (eql e 6)) (and (eql d 28) (eql e 6) (> a 10))) | ||
(setf e -1)) | ||
(values | ||
;; determination of the correct month for Easter | ||
(if (> (+ 22 d e) 31) | ||
(format nil "April ~a" (+ d e -9)) | ||
(format nil "March ~a" (+ 22 d e))) | ||
;; optionally return a value for the Servois' table | ||
(if servois (mod (+ 21 d) 31))))) | ||
|
||
(format t "~{~a~%~}" | ||
'("The following are the dates of the Paschal full moon (using Servois" | ||
"notation) and the date of Easter for 2020-2030 AD:~%" | ||
"Year Servois number Easter")) | ||
(loop for year from 2020 to 2030 do | ||
(multiple-value-bind (easter servois) (computus year t) | ||
(format t "~8a~18a~a~%" year servois easter))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to do the same thing as in the Rust implementation where you can use a conditional as an expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit tricky to do that, because the value of e is necessary for the conditional. I could definitely do it, but I feel it wouldn't help much. The Rust implementation also has to calculate a temp_e to make it work out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, not worth it then.