Created
July 20, 2012 06:05
-
-
Save NalaGinrut/3148977 to your computer and use it in GitHub Desktop.
the shortest snake arrange algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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