Advertisement
Guest User

Untitled

a guest
Nov 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. def main(args: Array[String]) {
  2. var tab:Array[Int] = Array.fill[Int](6)(0)
  3. remplTab(tab, 0)
  4. println(permutations.map(_.mkString(" ")).mkString("\n"))
  5. println("fin");
  6. }
  7.  
  8. var permutations:List[Array[Int]] = Nil;
  9.  
  10. def remplTab(tab : Array[Int], r:Int){
  11. if (r >= tab.length) {
  12. permutations = tab::permutations
  13. }
  14. else {
  15. for (i: Int <- 1 to tab.length) {
  16. if (!tab.contains(i)) {
  17. tab(r) = i;
  18. }
  19. }
  20. remplTab(tab, r+1)
  21. }
  22. }
  23.  
  24. def correcte(tab : Array[Int], lignes:Int) : Boolean = {
  25. for (i:Int <- 1 to lignes - 1)
  26. for (j:Int <- 1 to i)
  27. if (tab(indiceLigne(i,j)) != (tab(indiceLigne(i+1,j)) - tab(indiceLigne(i+1, j+1))).abs)
  28. return false
  29. return true
  30. }
  31.  
  32. def indiceLigne(ligne:Int, col:Int) : Int = {
  33. return (ligne*(ligne-1))/2+col-1
  34. }
  35.  
  36.  
  37. var permutations:List[Array[Int]] = Nil;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement