# Combining list in a Cartesian product format with addition operation?

I have two list to begin with.

list1 = {1, 2, 3};
list2 = {10, 20, 30, 40};


I want to obtain the following output (order unimportant):

{11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43}


I can obtain it via "Table, For, Do" etc. command but I am looking for a concise code to achieve such an output?

Outer[Plus, list2, list1] // Flatten


Tuples @ Unevaluated[{10, 20, 30, 40} + {1,2,3}]


{11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43}

Total[Tuples[{list2, list1}], {2}]
(* {11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43} *)

list1+#&/@list2//Flatten

(*{11,12,13,21,22,23,31,32,33,41,42,43}*)


Using Thread: (and letting it morph into MapThread)

Sequence @@@ (Thread[# + list1] & /@ list2)

Sequence @@@ (Map[Thread[# + list1] &, list2])

Sequence @@@


Result:

{11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43}

l1 = {1, 2, 3};
l2 = {10, 20, 30, 40};


Using SubsetMap:

f = Table[#, Length@l1 + 1] + Range@Length@# &;

(*{11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43}*)


Another very nice solution (Thanks to @Syed!) is the following:

Flatten@Thread[# + l2 & /@ l1]

(*{11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43}*)

• simpler: Flatten@Thread[# + l2 & /@ l1]. I am trying to say that SubsetMap[...,All] implies that Map can be used instead.
– Syed
Jan 31 at 4:44
• Clever solution, Syed! :-) Jan 31 at 4:46