Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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))
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement