START ESCWYP MUSIC VIDEOS
------------------------------------------------- permut.guile -----------------------
;; To run it:
;; guile -s permut.guile 5

(define (freespot ind)
   (when (>= ind 0)
      (bitvector-set! f ind #t)
      (when (<= ind minfree)
         (set! minfree ind)
      )
   )
)
(define (takespot ind)
   (when (>= ind 0)
      (bitvector-set! f ind #f)
      (when (= ind minfree)
         (let ((i (bit-position #t f (+ minfree 1))))
            (when (number? i)
               (set! minfree i)
            )
         )
      )
   )
)
(define (perm)
   (define count 1)
   (define start 1)
   (define j 0)
   (while (>= index 0)
      (set! start (+ (vector-ref c index) 1))
      (when (= start 0)
         (set! start minfree)
      )
      (set! start (bit-position #t f start))
      (when (number? start)
          (freespot (vector-ref c index))
          (takespot start)
          (vector-set! c index start)
          (if (< index (- num 1))
             (set! index (+ index 1))
             (begin
                (freespot start)
                (if (> num 100)
                  (begin
                     (do ((j 0 (+ 1 j)))
                        ((> j 10))
                        (display (vector-ref c j))
                        (display " ")
                     )
                     (display " ... ")
                     (do ((j (- num 10) (+ 1 j)))
                        ((= j num))
                        (display (vector-ref c j))
                        (display " ")
                     )
                  )
                  (begin
                     (do ((j 0 (+ 1 j)))
                        ((= j num))
                        (display (vector-ref c j))
                        (display " ")
                     )
                  )
               )
               (display "| ")
               (display count)
               (newline)
               (set! count (+ count 1))
            )
         )
      )
      (when (= index old)
         (freespot (vector-ref c index))
         (vector-set! c index -1)
         (set! index (- index 1))
      )
      (set! old index)
   )
)

(define index 0)
(define old 0)
(define minfree 0)
(define num 2)
(when (> (length (command-line)) 1)
   (set! num (string->number (cadr (command-line))))
)
(when (or (not (integer? num)) (< num 2))
   (set! num 2)
)
(display num)
(newline)
(define f (make-bitvector num #t))
(define c (make-vector num -1))
(perm)

START ESCWYP MUSIC VIDEOS