Skip to content

Instantly share code, notes, and snippets.

@Sciss
Last active February 19, 2018 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sciss/3a243b11ea0302f97cfb824ea1ff9f21 to your computer and use it in GitHub Desktop.
Save Sciss/3a243b11ea0302f97cfb824ea1ff9f21 to your computer and use it in GitHub Desktop.
def selectEdges(nv: Int = 18, ne: Int = 12) = {
var m = Map.empty[Int, Set[Int]] withDefaultValue Set.empty
val vr = (1 to nv)
vr.reverse.foreach { v =>
val s0 = m(v)
val cand0 = vr.filterNot(s0.contains)
val cand1 = cand0.filter { v2 => m(v2).size < ne }
val tk = ne - s0.size
val cand = cand1.take(tk)
assert (cand.size == tk, s"Woops. wanted $tk got ${cand.size}")
val s1 = s0 ++ cand
m = m + (v -> s1)
cand.foreach { v2 =>
val s2 = m(v2)
val s3 = s2 + v
m = m + (v2 -> s3)
}
}
m
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment