Created
October 28, 2011 01:53
-
-
Save kanghyojun/1321440 to your computer and use it in GitHub Desktop.
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
(define (get-list l n) | |
(if (= n 0) | |
(car l) | |
(get-list (cdr l) (- n 1)))) | |
(define (r-gen l n range) | |
(if (= n 1) | |
(r-append l range) | |
(r-gen (r-append l range) (- n 1) range))) | |
(define (r-append l r) | |
(let ((r-num (random r))) | |
(if (num-exists? l r-num) | |
(r-append l r) | |
(append l (list r-num))))) | |
(define (num-exists? l f) | |
(if (find-num l f (length l)) | |
#t #f)) | |
(define (find-num l f len) | |
(let ((idx (- len 1))) | |
(if (< idx 0) | |
#f | |
(if (= (get-list l idx) f) | |
#t | |
(find-num l f idx))))) | |
(define (swap-list l swp-idx) | |
(let ( (left (add-til l 1 swp-idx)) (right (add-til l swp-idx (length l))) (swp (car l)) ) | |
(append left (list swp) right) | |
) | |
) | |
(define (add-til l s til) | |
(if (< s til) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment