summaryrefslogtreecommitdiffstats
path: root/net/ricketyspace
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2019-07-16 18:39:20 -0400
committerrsiddharth <s@ricketyspace.net>2019-07-16 18:39:20 -0400
commitd3e3134b15f55329760ac92e09d08738ab97cfbf (patch)
tree457389da775e53c8e9e218521d0f08cede748b0d /net/ricketyspace
parent6bf176f3e091328ceb43de82b6514a23ccef755e (diff)
two/twentynine.scm: Add example for mobile-balanced?
Diffstat (limited to 'net/ricketyspace')
-rw-r--r--net/ricketyspace/sicp/two/twentynine.scm57
1 files changed, 57 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/two/twentynine.scm b/net/ricketyspace/sicp/two/twentynine.scm
index 8b763ea..0bad7f2 100644
--- 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