Create a gist now

Instantly share code, notes, and snippets.

@Knium /tree-diagram.scm Secret
Created May 24, 2018

Embed
(define (print-tree-diagram p1 p2 str)
(cond ((and (null? p1) (null? p2)) (print str))
((null? p1) (print-tree-diagram p1 (cdr p2) (string-append str (car p2))))
((null? p2) (print-tree-diagram (cdr p1) p2 (string-append str (car p1))))
(else (print-tree-diagram (cdr p1) p2 (string-append str (car p1)))
(print-tree-diagram p1 (cdr p2) (string-append str (car p2))))))
(print-tree-diagram (list "a" "b" "c" "d") (list "x" "y" "z") "")
; abcdxyz
; abcxdyz
; abcxydz
; abcxyzd
; abxcdyz
; abxcydz
; abxcyzd
; abxycdz
; abxyczd
; abxyzcd
; axbcdyz
; axbcydz
; axbcyzd
; axbycdz
; axbyczd
; axbyzcd
; axybcdz
; axybczd
; axybzcd
; axyzbcd
; xabcdyz
; xabcydz
; xabcyzd
; xabycdz
; xabyczd
; xabyzcd
; xaybcdz
; xaybczd
; xaybzcd
; xayzbcd
; xyabcdz
; xyabczd
; xyabzcd
; xyazbcd
; xyzabcd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment