# Struggling to Apply "Differences" [duplicate]

It looks like the following code should work, and allow it spits out error messages saying I have too many arguments, the code spit out after the error message looks like exactly what I want to calculate, but it won't give the answers. Completely stumped here...

list[b_, c_] := Table[{a, b, c}, {a, 0, c - 1}];
list2 = Tuples[Table[list[Prime[8], c], {c, 5, 7}]];

list3[a_, b_, c_] := Union[
Range[a, b, Prime[c]],
Range[a + 2, b, Prime[c]]]

list4 = Union @@@ Apply[list3, list2, {2}];
Apply[Differences, list4, 1]


Here's the output:

{Differences[0, 2, 11, 13, 15, 17, 19],
Differences[0, 1, 2, 3, 11, 13, 15, 18],
Differences[0, 2, 4, 11, 13, 15, 19],
Differences[0, 2, 3, 5, 11, 13, 15],
Differences[0, 2, 4, 6, 11, 13, 15],
Differences[0, 2, 5, 7, 11, 13, 15],...


Those are the differences I want. How do I get it to spit them out?

• Why are you applying? This should be mapped...
– ciao
May 25, 2016 at 22:48
• @ciao Sorry, I'm new. What do you mean? May 25, 2016 at 22:49
• Map[Differences, list4] or just Differences/@list4
– ciao
May 25, 2016 at 22:50
• @ciao That did it! Would you post as an answer with an explanation of the difference :-) between apply and map? May 25, 2016 at 22:53

Map[Differences, list4] or just Differences/@list4
Map takes the sub-lists of list4 as the argument to Differences for each, Applyreplaces the heads (List) on the sub-lists with Differences (so the elements of the list all become arguments to Differences), hence the error message: Differences expects a list (and optional remaining arguments up to 3 total arguments), but you are feeding it the list elements themselves.