Skip to content

Instantly share code, notes, and snippets.

@vedantk
Created January 13, 2012 21:47
Show Gist options
  • Save vedantk/1608876 to your computer and use it in GitHub Desktop.
Save vedantk/1608876 to your computer and use it in GitHub Desktop.
The call/cc yin yang puzzle extended to arbitrarily large n.
(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