Created
January 13, 2012 21:47
-
-
Save vedantk/1608876 to your computer and use it in GitHub Desktop.
The call/cc yin yang puzzle extended to arbitrarily large n.
This file contains hidden or 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 (yin-yang n) | |
(define yv | |
(for/vector ([i (in-range n)]) | |
((lambda (cc) (printf "~a " i) cc) (call/cc (lambda (k) k))))) | |
(for ([i (in-range (- n 1))]) | |
((vector-ref yv i) (vector-ref yv (+ i 1))))) | |
;; > (yin-yang 0) | |
;; > (yin-yang 1) | |
;; 0 | |
;; > (yin-yang 2) | |
;; 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 ... | |
;; > (yin-yang 7) | |
;; 0 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 0 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 0 ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment