Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. def perms(positions: List[Int]) = {
  2. val x: Set[List[Int]] = positions.permutations.map(_.take(2)).toSet
  3.  
  4. val y = x filter {
  5. case a :: b :: Nil =>
  6. (a, b) match {
  7. case (a: Int, b: Int) if a < b => true
  8. case _ => false
  9. }
  10. case _ => false
  11. }
  12.  
  13. System.out.println(y)
  14. }
  15.  
  16. (4 until 9) foreach { length =>
  17. perms((0 until length).toList)
  18. }
  19.  
  20. /*
  21. Output:
  22. Set(List(1, 2), List(2, 3), List(0, 2), List(0, 1), List(1, 3), List(0, 3))
  23. 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))
  24. 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))
  25. 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))
  26. 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))
  27. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement