Friday 15 May 2015

Multiply nested pairs of list values in Clojure -


I'm finally trying to do, increases two vectors together and returns to a vector of the same size As is:

  [6 7 8 9 10] * [0 1 3 1 0] => [0 7 24 9]  

I was trying to do something like this:

  (Partition 2 (Interleave [6 7 8 9 10] [0 1 3 1 0])) =) (6 0) (7 1) (8 3) (9 1) (10 0))  

... then multiply each nested list value and flatten To get:

  (0 7 24 9)  

But I can not understand how I can increase nested list values ?

In order to combine each sequence with the respective member of the other sequences, more than one sequence and one Takes the function.

<> User & gt; (Map * [6 7 8 9 10] [0 1 3 1 0]) (0 7 2490) User & gt; (Map * * [6 7 8 9 10] [0 1 3 1 0]) [0 7 24 9]

In this case, this code will be sent to * Creates a number of calls from each list first, then from each list to another, and so on, if you prefer output in a vector mapv it is convenient


No comments:

Post a Comment