Created
May 18, 2015 14:02
-
-
Save fabienhinault/3563f10f8ac901a83097 to your computer and use it in GitHub Desktop.
chinese rings in racket (baguenaudier ou baguenodier en français)
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 rings-repl | |
| (let ((rings '(#f #f #f #f))) | |
| (λ () | |
| (displayln rings) | |
| (set! rings (eval (list (read) `(quote ,rings)))) | |
| (rings-repl)))) | |
| (define (b rings) | |
| (cond | |
| ((null? rings) '()) | |
| ((null? (cdr rings)) rings) | |
| ((car rings) (list* #t (not (cadr rings)) (cddr rings))) | |
| (#t (cons #f (b (cdr rings)))))) | |
| (define (a rings) | |
| (cons (not (car rings)) (cdr rings))) | |
| ;> (rings-repl) | |
| ;(#f #f #f #f) | |
| ;a | |
| ;(#t #f #f #f) | |
| ;a | |
| ;(#f #f #f #f) | |
| ;b | |
| ;(#f #f #f #f) | |
| ;a | |
| ;(#t #f #f #f) | |
| ;b | |
| ;(#t #t #f #f) | |
| ;a | |
| ;(#f #t #f #f) | |
| ;b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment