How to count square matrix represented as vectors in clojure -
assume two-dimensional matrix represented vector of vectors, such innermost vectors each represent row in matrix . two-dimensional matrix square if number of rows equal number of columns.
why loop-recur constraint?
if can assume every row same size (regular structure), work:
(defn is-square [m] (= (count m) (count (first m))))
if want check every row:
(defn is-square [m] (apply = (count m) (map count m)))
if really want use loop-recur reason:
(defn is-square [m] (loop [[row & more] m] (if row (if (= (count row) (count m)) (recur more) false) true)))
Comments
Post a Comment