sicp

sicp sandbox.
git clone git://git.ricketyspace.net/sicp.git
Log | Files | Refs

commit d3e3134b15f55329760ac92e09d08738ab97cfbf
parent 6bf176f3e091328ceb43de82b6514a23ccef755e
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue, 16 Jul 2019 18:39:20 -0400

two/twentynine.scm: Add example for mobile-balanced?

Diffstat:
net/ricketyspace/sicp/two/twentynine.scm | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+), 0 deletions(-)

diff --git a/net/ricketyspace/sicp/two/twentynine.scm b/net/ricketyspace/sicp/two/twentynine.scm @@ -85,3 +85,60 @@ ;;; $20 = (1 20) ;;; scheme@(guile-user)> (total-weight $11) ;;; $21 = 115 +;;; +;;; scheme@(guile-user)> (make-mobile (make-branch 5 50) (make-branch 5 50)) +;;; $37 = ((5 50) (5 50)) +;;; scheme@(guile-user)> (mobile-balanced? $37) +;;; $38 = #t +;;; scheme@(guile-user)> (make-mobile (make-branch 5 50) (make-branch 5 48)) +;;; $39 = ((5 50) (5 48)) +;;; scheme@(guile-user)> (mobile-balanced? $39) +;;; $40 = #f +;;; scheme@(guile-user)> (make-mobile (make-branch 6 +;;; (make-mobile (make-branch 2 25) +;;; (make-branch 2 25))) +;;; (make-branch 6 50)) +;;; $41 = ((6 ((2 25) (2 25))) (6 50)) +;;; scheme@(guile-user)> (mobile-balanced? $41) +;;; $42 = #t +;;; scheme@(guile-user)> (make-mobile (make-branch 6 +;;; (make-mobile (make-branch 2 24) +;;; (make-branch 2 25))) +;;; (make-branch 6 50)) +;;; $43 = ((6 ((2 24) (2 25))) (6 50)) +;;; scheme@(guile-user)> (mobile-balanced? $43) +;;; $44 = #f +;;; scheme@(guile-user)> (make-mobile (make-branch 3 +;;; (make-mobile +;;; (make-branch 10 +;;; (make-mobile +;;; (make-branch 10 +;;; (make-mobile +;;; (make-branch 20 10) +;;; (make-branch 10 +;;; (make-mobile +;;; (make-branch 2 10) +;;; (make-branch 2 10))))) +;;; (make-branch 30 10))) +;;; (make-branch 40 10))) +;;; (make-branch 3 50)) +;;; $45 = ((3 ((10 ((10 ((20 10) (10 ((2 10) (2 10))))) (30 10))) (40 10))) (3 50)) +;;; scheme@(guile-user)> (mobile-balanced? $45) +;;; $46 = #t +;;; scheme@(guile-user)> (make-mobile (make-branch 3 +;;; (make-mobile +;;; (make-branch 10 +;;; (make-mobile +;;; (make-branch 2 +;;; (make-mobile +;;; (make-branch 20 10) +;;; (make-branch 10 +;;; (make-mobile +;;; (make-branch 2 10) +;;; (make-branch 2 10))))) +;;; (make-branch 30 10))) +;;; (make-branch 40 10))) +;;; (make-branch 3 50)) +;;; $47 = ((3 ((10 ((2 ((20 10) (10 ((2 10) (2 10))))) (30 10))) (40 10))) (3 50)) +;;; scheme@(guile-user)> (mobile-balanced? $47) +;;; $48 = #f