Skip to content

Instantly share code, notes, and snippets.

@simbo1905
Last active March 29, 2017 17:04
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 simbo1905/868d7defeb3c075f584753b0153d58e1 to your computer and use it in GitHub Desktop.
Save simbo1905/868d7defeb3c075f584753b0153d58e1 to your computer and use it in GitHub Desktop.
def perms(positions: List[Int]) = {
val x: Set[List[Int]] = positions.permutations.map(_.take(2)).toSet
val y = x filter {
case a :: b :: Nil =>
(a, b) match {
case (a: Int, b: Int) if a < b => true
case _ => false
}
case _ => false
}
System.out.println(y)
}
(4 until 9) foreach { length =>
perms((0 until length).toList)
}
/*
Output:
Set(List(1, 2), List(2, 3), List(0, 2), List(0, 1), List(1, 3), List(0, 3))
Set(List(3, 4), List(1, 2), List(2, 3), List(1, 4), List(0, 4), List(0, 2), List(2, 4), List(0, 1), List(1, 3), List(0, 3))
Set(List(3, 4), List(0, 5), List(1, 2), List(2, 3), List(1, 4), List(0, 4), List(0, 2), List(2, 4), List(0, 1), List(1, 5), List(2, 5), List(4, 5), List(1, 3), List(3, 5), List(0, 3))
Set(List(3, 4), List(0, 5), List(1, 2), List(2, 3), List(1, 4), List(5, 6), List(0, 4), List(0, 2), List(2, 4), List(0, 1), List(1, 6), List(1, 5), List(2, 5), List(4, 5), List(2, 6), List(1, 3), List(3, 5), List(0, 3), List(4, 6), List(3, 6), List(0, 6))
Set(List(3, 4), List(0, 5), List(1, 2), List(2, 3), List(1, 4), List(5, 6), List(0, 4), List(1, 7), List(0, 2), List(4, 7), List(2, 7), List(2, 4), List(0, 1), List(0, 7), List(1, 6), List(6, 7), List(1, 5), List(2, 5), List(5, 7), List(4, 5), List(2, 6), List(1, 3), List(3, 5), List(0, 3), List(4, 6), List(3, 7), List(3, 6), List(0, 6))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment