Skip to content

Instantly share code, notes, and snippets.

@fabienhinault
Created May 18, 2015 14:02
Show Gist options
  • Save fabienhinault/3563f10f8ac901a83097 to your computer and use it in GitHub Desktop.
Save fabienhinault/3563f10f8ac901a83097 to your computer and use it in GitHub Desktop.
chinese rings in racket (baguenaudier ou baguenodier en français)
(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