Albero di Steinhaus in Scheme
AVVISO! Le informazioni di questo post potrebbero non essere più valide in quanto non aggiornate. Usa i commenti per contribuire a tenere il post aggiornato.
ULTIMA REVISIONE DEL POST: 24/04/2014
Vedi un esempio dell’albero di Steinhaus con Scheme (lisp Language):
(define nxt (lambda (sq op) (let ((n (string-length sq))) (if (= n 1) "" (string-append (if (op (string-ref sq 0) (string-ref sq 1)) (string-append (string #\0) (nxt (substring sq 1) op)) (string-append (string #\1) (nxt (substring sq 1) op)) ) ) )))) (define tri (lambda (sq op) (if (= (string-length sq) 1) (list sq) (cons sq (tri (nxt sq op) op)) ))) (tri "1101" char=? )
Altra soluzione potrebbe essere questa, più complessa da capire, ma più semplice da implementare!
(define nxt (lambda (sq op) (let ((n (string-length sq))) (if (= n 1) "" (string-append (op (string-ref sq 0) (string-ref sq 1)) (nxt (substring sq 1) op)) )))) (define tri (lambda (sq op) (if (= (string-length sq) 1) (list sq) (cons sq (tri (nxt sq op) op)) ))) (tri "1101" (lambda (u v) (if (char=? u v) "0" "1")))