Skip to content

Instantly share code, notes, and snippets.

@Sciss
Last active February 18, 2018 21:48
Show Gist options
  • Save Sciss/a1a6f769a29003c5d7b9b1696d162c82 to your computer and use it in GitHub Desktop.
Save Sciss/a1a6f769a29003c5d7b9b1696d162c82 to your computer and use it in GitHub Desktop.
// given the number of edges of a complete graph,
// determine the number of vertices. will be integer,
// if this is a complete graph.
//
// solves edges = vertices * (vertices - 1) / 2
def vertices(edges: Int): Double = {
val q = -2 * edges
val ph = -0.5
val phs = 0.25
val r = math.sqrt(phs - q)
val x1 = -ph + r x1
}
val ex = (1 to 200).flatMap { e => val v = vertices(e); val vi = v.toInt; if (v == vi) Some(e -> vi) else None }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment