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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -