START ESCWYP MUSIC VIDEOS
------------------------------------------------- permut.go -----------------------
package main
import "fmt"
import "os"
import "strconv"

func freespot(ind int, num int, minfree *int, f *[]bool){
   if ind >= 0 && ind < num {
      (*f)[ind] = true
      if ind < *minfree {
         *minfree = ind
      }
   }
}
func takespot(ind int, num int, minfree *int, f *[]bool){
   if ind >= 0 && ind < num {
      (*f)[ind] = false
      if ind == *minfree {
         for i:=(*minfree)+1; i < num; i++ {
            if (*f)[i] == true {
               *minfree = i
               break
            }
         }
      }
   }
}

func main(){

   num := 2
   old := 0
   index := 0
   minfree := 0
   if len(os.Args) > 1{
      tmp,err := strconv.Atoi(os.Args[1])
      if err == nil && tmp > 1{
         num = tmp
      }
   }
   f := make([]bool, num)
   c := make([]int, num)
   for i:= 0; i < num; i++{
      f[i] = true
      c[i] = -1
   }
   fmt.Println("init fertig", num)

   count := 1
   for index >= 0 {
      start := c[index]+1
      if start == 0 {
         start = minfree
      }
      for i:=start; i < num; i++ {
         if f[i] == true {
            freespot(c[index], num, &minfree, &f)
            takespot(i, num, &minfree, &f)
            c[index] = i
            if index < num-1 {
               index++
            }else{
               freespot(i, num, &minfree, &f)
               if num > 100 {
                  for j:=0;j < 10; j++ {
                     fmt.Print(c[j], " ")
                  }
                  fmt.Print("... ")
                  for j:=num-10;j < num; j++ {
                     fmt.Print(c[j], " ")
                  }
               }else{
                  for j:=0;j < num; j++ {
                     fmt.Print(c[j], " ")
                  }
               }
               fmt.Println(" | ", count)
               count++
            } 
            break
         }
      }
      if index == old {
         freespot(c[index], num, &minfree, &f)
         c[index] = -1
         index--
      }
      old = index
   }
}


START ESCWYP MUSIC VIDEOS