diff options
author | Daniel Santos <dacs.git@brilhante.top> | 2023-01-13 18:00:30 +0000 |
---|---|---|
committer | Daniel Santos <dacs.git@brilhante.top> | 2023-01-14 11:54:55 +0000 |
commit | fbf5e7e1db52d4fc9ccb14366768287482ea8758 (patch) | |
tree | a9eff63308d00e6a592e6d77989bfce1e79115c0 | |
parent | 9514c346af1789f9f26fa23edc555724d9eede87 (diff) | |
download | cl-math-fbf5e7e1db52d4fc9ccb14366768287482ea8758.tar.gz |
add may-reverse-and-cut
-rw-r--r-- | plus-inc.lisp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/plus-inc.lisp b/plus-inc.lisp index 3d85b11..cabc2d3 100644 --- a/plus-inc.lisp +++ b/plus-inc.lisp @@ -12,6 +12,12 @@ (defun may-reverse (number) "If units is placed on the end, reverse; else keep it." (if *number-units-at-beginning* + number + (reverse number))) + +(defun may-reverse-and-cut (number) + "If units is placed on the end, reverse; else keep it. Also cuts unecessary digits." + (if *number-units-at-beginning* (reverse (cut-digits (reverse number))) (reverse (cut-digits number)))) @@ -82,12 +88,12 @@ (defun plus (numerals a b) "Given a list of a numeral system and 2 lists of symbols, it returns the list of it's sum." - (may-reverse (plus-args-list numerals (may-reverse a) (may-reverse b)))) + (may-reverse (plus-args-list numerals (may-reverse-and-cut a) (may-reverse-and-cut b)))) (defun plus-decimal (&rest args) "Given decimal numbers, it returns the symbol it's sum." - (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|0| |1| |2| |3| |4| |5| |6| |7| |8| |9|) a b)) (mapcar #'may-reverse (mapcar #'explode args))))))) + (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|0| |1| |2| |3| |4| |5| |6| |7| |8| |9|) a b)) (mapcar #'may-reverse-and-cut (mapcar #'explode args))))))) (defun plus-earth (&rest args) "Give earthal numbers, it returns it's sum." - (symbol-to-number (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|1| |2| |3| |4| |5|) a b)) (mapcar #'may-reverse (mapcar #'explode args)))))))) + (symbol-to-number (nth-value 0 (implode (may-reverse (reduce (lambda (a b) (plus-args-list '(|1| |2| |3| |4| |5|) a b)) (mapcar #'may-reverse-and-cut (mapcar #'explode args)))))))) |