Skip to content

Instantly share code, notes, and snippets.

@NalaGinrut
Created July 20, 2012 06:05
Show Gist options
  • Save NalaGinrut/3148977 to your computer and use it in GitHub Desktop.
Save NalaGinrut/3148977 to your computer and use it in GitHub Desktop.
the shortest snake arrange algorithm
#! /usr/local/bin/guile \
-e main -s
!#
(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 (append (list 1 (car b)) (cdr a)) (append (cdr b) (list (list-ref a m))) (1+ n))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment