I have a list of lists, and I want to eliminate all the lists that are constant integer multiples of another list. My initial approach was to divide the lists using nested tables.
ex1 = {{1, 1, 1}, {1, 1, 2}, {2, 2, 2}, {2, 2, 4}, {3, 3, 5}};
Table[Table[
If[Subtract @@ MinMax[ex1[[j]]/ex1[[i]]] == 0,
ex1[[j]] = ex1[[i]]], {j, i + 1, Length[ex1]}], {i, Length[ex1]}];
Union[ex1]
{{1, 1, 1}, {1, 1, 2}, {3, 3, 5}}
However, some of my lists have zeroes, which breaks my code.
ex2 = {{1, 1, 0}, {1, 1, 2}, {2, 2, 0}, {2, 2, 4}, {3, 3, 5}};
Table[Table[
If[Subtract @@ MinMax[ex2[[j]]/ex2[[i]]] == 0,
ex2[[j]] = ex2[[i]]], {j, i + 1, Length[ex2]}], {i, Length[ex2]}];
Union[ex2]
"CHAOS ENSUES"
I have an alternative approach which is stupid and ugly.
ex3 = {{1, 1, 0}, {1, 1, 2}, {2, 2, 0}, {2, 2, 4}, {3, 3, 5}};
Table[
Table[
Table[
If[ex3[[i]]*k == ex3[[j]], ex3[[j]] = ex3[[i]]], {k, j}],
{j, i + 1, Length[ex3]}],
{i, Length[ex3]}];
Union[ex3]
{{1, 1, 0}, {1, 1, 2}, {3, 3, 5}}
I'm certain there's a better way, but I can't come up with it. I was frustrated by the ugliness of with my first attempt, but at least it was somewhat clever. Can you suggest something nicer?
