Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I multiply all elements in one collection with all the elements in another collection?

Tags:

clojure

Say I have:

(def s1 [1 2 3 4 5])
(def s2 [1 2 3 4 5])

For every x in s1, I want to multiply it with every y in s2.


To clarify, I basically want the Cartesian product, so I don't think map works here.

like image 202
Blaine Lafreniere Avatar asked Jul 23 '10 21:07

Blaine Lafreniere


1 Answers

(for [x1 s1
      x2 s2]
  (* x1 x2))
like image 148
Michał Marczyk Avatar answered Oct 05 '22 01:10

Michał Marczyk