This code produces straight lines, I'd like to find which n values are on which of the lines:

  Table[PrimePi[Min[Prime[n + 1]^2, Product[Prime@i, {i, n}]]] - 
    n, {n, 3000}]]]

enter image description here

Is there a way to sort the n values accurately for a general case of multiple straight or curved lines?

cheers, Jamie


1 Answer 1


The angles of the points capture rather well their belonging to one line or another. Combine that with Mathematica's clustering algorithms and you have a possible way of solving this:

data = Differences[Table[PrimePi[Min[Prime[n + 1]^2, Product[Prime@i, {i, n}]]] - n, {n, 3000}]];
pts = Transpose[{Range@Length[data], data}];
angles = ArcTan @@@ pts;
clusters = FindClusters[angles -> pts, Method -> "Agglomerate"];

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.