From fbf5e7e1db52d4fc9ccb14366768287482ea8758 Mon Sep 17 00:00:00 2001 From: Daniel Santos Date: Fri, 13 Jan 2023 18:00:30 +0000 Subject: add may-reverse-and-cut --- plus-inc.lisp | 12 +++++++++--- 1 file 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 @@ -11,6 +11,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)))))))) -- cgit 1.4.1-2-gfad0