Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Pyramide {
- var permutations:List[Array[Int]] = Nil;
- def remplTab(tab : Array[Int], r:Int){
- if (r >= tab.length)
- {
- permutations = tab::permutations
- }
- else {
- for (i: Int <- 1 to tab.length) {
- if (!tab.contains(i)) {
- tab(r) = i;
- }
- }
- remplTab(tab, r+1)
- }
- }
- def correcte(tab : Array[Int], lignes:Int) : Boolean = {
- for (i:Int <- 1 to lignes - 1)
- for (j:Int <- 1 to i)
- if (tab(indiceLigne(i,j)) != (tab(indiceLigne(i+1,j)) - tab(indiceLigne(i+1, j+1))).abs)
- return false
- return true
- }
- def indiceLigne(ligne:Int, col:Int) : Int = {
- return (ligne*(ligne-1))/2+col-1
- }
- def main(args: Array[String]): Unit = {
- var tab:Array[Int] = Array.fill[Int](6)(0)
- remplTab(tab, 0)
- println(permutations.map(_.mkString(" ")).mkString("\n"))
- println("fin");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement