From b414870e702c78e9a922b47989466a8f88e0b13e Mon Sep 17 00:00:00 2001 From: mehbark Date: Sun, 15 Jan 2023 20:31:36 -0500 Subject: [PATCH] add human-readable indices (starting at 1) --- src/matrix/auto.clj | 1 - src/matrix/core.clj | 2 +- src/matrix/render.clj | 24 +++++++++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/matrix/auto.clj b/src/matrix/auto.clj index 8aa96ac..dbe4df4 100644 --- a/src/matrix/auto.clj +++ b/src/matrix/auto.clj @@ -68,7 +68,6 @@ [] (let [steps (back-sub-column m col) new (apply-all-at-once m steps)] - (println new) (concat steps (back-sub new (dec col))))))) (defn auto-steps-and-final diff --git a/src/matrix/core.clj b/src/matrix/core.clj index 8bcb5ef..c051ae4 100644 --- a/src/matrix/core.clj +++ b/src/matrix/core.clj @@ -13,7 +13,7 @@ (println "Steps:") ;; (for [step steps] ;; (println (pretty-row-op step))) - (println (str/join "\n" (map pretty-row-op steps))) + (println (str/join "\n" (map with-inc-row-indices steps))) (println "Final:") (pprint-matrix final))) diff --git a/src/matrix/render.clj b/src/matrix/render.clj index 889e3b3..dbd180e 100644 --- a/src/matrix/render.clj +++ b/src/matrix/render.clj @@ -169,11 +169,25 @@ " + " "R" (shrink-number (:to-row op))))) -(defn pretty-row-op - "Returns a pretty string of a row operation" +(defn with-inc-row-indices + "Prettify a row-op with human-readable-indices" [op] (if-let [[op-type inner] (conform op)] (case op-type - :swap (pretty-swap inner) - :mul (pretty-mul inner) - :add (pretty-add inner)))) + :swap (pretty-swap (-> inner + (update :swap + 1) + (update :with + 1))) + :add (pretty-add (-> inner + (update :add-row + 1) + (update :to-row + 1))) + :mul (pretty-mul (update inner :mul-row + 1))))) + +(defn pretty-row-op + "Returns a pretty string of a row operation" + ([op] + (if-let [[op-type inner] (conform op)] + (case op-type + :swap (pretty-swap inner) + :mul (pretty-mul inner) + :add (pretty-add inner)))) + ([op _] (with-inc-row-indices op)))