Advertisement
Guest User

Untitled

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