using Map to apply 2 lists to the LCM function – help [duplicate]

This question already has an answer here:

Operate on several lists to create one list

2 answers

I have 2 lists of numbers and I want to quickly compute the array of answers to the LCM function for the 2 lists and a 3rd static number. I tried the following

list1 = {2,3,5,10};
list2 = {5,10,30,70};
LCM[37, #1, #2] & /@ [list1, list2]

but got a cryptic error message that I don’t understand. Can anyone help or point me to the correct area?

Many thanks in advance

=================

=================

2 Answers
2

=================

You can use Outer along with Map.

Map[LCM[37, Sequence @@ #] &, Outer[List, list1, list2], {2}]
(*
{{370, 370, 1110, 2590},
{555, 1110, 1110, 7770},
{185, 370, 1110, 2590},
{370, 370, 1110, 2590}}
*)

Hope this helps.

Or as @SimonWood has pointed out in the comments.

Outer[LCM[37, ##] &, list1, list2]

3

 

Why not just Outer[LCM[37, ##] &, list1, list2] ?
– Simon Woods
Feb 3 at 21:27

  

 

@SimonWoods Yes. You are completely correct. My solution-by-parts needs a convolution boost today. LOL!!
– Edmund
Feb 3 at 21:30

  

 

LOL. I wondered if you were just determined to use Map as specified in the question title…
– Simon Woods
Feb 3 at 21:33

  

 

@SimonWoods Perhaps subconsciously. 😛
– Edmund
Feb 3 at 21:37

Example:

LCM[37, #[[1]], #[[2]]] & /@ Transpose[{list1, list2}]

or

MapThread[LCM[37, ##] &, {list1, list2}]

Output:

{370, 1110, 1110, 2590}

Reference:

& # /@ etc.
MapThread
Transpose