I get intrigued about Gather
behavior on this post.
I thought that Gather
was invariant under list order?
Here is the result I spect:
l1={{1, 1}, {0, 0}, {2, 2}, {5, 5}, {4, 4}, {6, 6}}
Gather[l1,ManhattanDistance[#1, #2] <= 2 &]
{{{1,1},{0,0},{2,2}},{{5,5},{4,4},{6,6}}}
When the list order is changed, I get this:
l2={{0, 0}, {1, 1}, {2, 2}, {4, 4}, {5, 5}, {6, 6}}
Gather[l2,ManhattanDistance[#1,#2]<= 2&]
{{{0,0},{1,1}},{{2,2}},{{4,4},{5,5}},{{6,6}}}
Someone know why?
{4,5}>{5,4}
or{4,5}<{5,4}
? $\endgroup$l2
the result{{{0,0}}, {{1,1}, {2,2}}, {{4,4}}, {{5,5}, {6,6}}}
is as good as the one you obtained. $\endgroup$False
. TryReap@Gather[l2, (Sow[{#, #2}]; ManhattanDistance[#1, #2] <= 2) &]
$\endgroup$