Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Modular-arithmetic/Common-Lisp/modular-arithmetic.lisp
Normal file
24
Task/Modular-arithmetic/Common-Lisp/modular-arithmetic.lisp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(defvar *modulus* nil)
|
||||
|
||||
(defmacro define-enhanced-op (enhanced-op op)
|
||||
`(defun ,enhanced-op (&rest args)
|
||||
(if *modulus*
|
||||
(mod (apply ,op args) *modulus*)
|
||||
(apply ,op args))))
|
||||
|
||||
(define-enhanced-op enhanced+ #'+)
|
||||
(define-enhanced-op enhanced-expt #'expt)
|
||||
|
||||
(defun f (x)
|
||||
(enhanced+ (enhanced-expt x 100) x 1))
|
||||
|
||||
;; Use f on regular integers.
|
||||
(princ "No modulus: ")
|
||||
(princ (f 10))
|
||||
(terpri)
|
||||
|
||||
;; Use f on modular integers.
|
||||
(let ((*modulus* 13))
|
||||
(princ "modulus 13: ")
|
||||
(princ (f 10))
|
||||
(terpri))
|
||||
Loading…
Add table
Add a link
Reference in a new issue