Skip to content

Instantly share code, notes, and snippets.

@jColeChanged
Created April 24, 2011 07:03
Show Gist options
  • Save jColeChanged/939383 to your computer and use it in GitHub Desktop.
Save jColeChanged/939383 to your computer and use it in GitHub Desktop.
My attempt at matrix multiplication in Clojure
(defn C_yx [m1 m2 y x num-cols num-rows]
(reduce +
(map *
(map #(nth (nth m1 y) %1) (range num-cols))
(map #(nth (nth m2 %1) x) (range num-rows)))))
(defn multiply [m1 m2]
(let [num-rows (count m1) num-cols (count (first m1))]
(for [y (range num-rows)]
(for [x (range num-cols)]
(C_yx m1 m2 y x num-rows num-cols)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment