Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Created July 20, 2012 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NalaGinrut/3148984 to your computer and use it in GitHub Desktop.
Save NalaGinrut/3148984 to your computer and use it in GitHub Desktop.
the shortest snake arrange algorithm (slow version)
(define (main . args)
(let* ((ll ((@ (srfi srfi-1) iota) (read) 1)) (len (length ll)) (m (1- (/ len 2))))
(display len)(newline)
(let lp((a (list-head ll (1+ m))) (b (list-tail ll (1+ m))) (n 1))
(and (< n len) (for-each (lambda (x y) (display x)(display " ")(display y)(display " ")) a b)(newline)
(lp `(1 ,(car b) ,@(cdr a)) `(,@(cdr b) ,(list-ref a m)) (1+ n))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment