From a2fc1fda91fbae99f3f14b3370ccd67871ac6c87 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Mon, 15 Jul 2019 19:19:48 -0400 Subject: net/ricketyspace: two/twentynine.scm: Add branch-weight. * net/ricketyspace/sicp/two/twentynine.scm (branch-weight): New function. (total-weight): Remove branch-weight local function. --- net/ricketyspace/sicp/two/twentynine.scm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'net') diff --git a/net/ricketyspace/sicp/two/twentynine.scm b/net/ricketyspace/sicp/two/twentynine.scm index cc1380c..8e1aaa2 100644 --- a/net/ricketyspace/sicp/two/twentynine.scm +++ b/net/ricketyspace/sicp/two/twentynine.scm @@ -27,12 +27,13 @@ (define (branch-structure branch) (car (cdr branch))) +(define (branch-weight b) + (let ((bs (branch-structure b))) + (cond ((not (pair? bs)) bs) + (else (+ (branch-weight (left-branch bs)) + (branch-weight (right-branch bs))))))) + (define (total-weight mobile) - (define (branch-weight b) - (let ((bs (branch-structure b))) - (cond ((not (pair? bs)) bs) - (else (+ (branch-weight (left-branch bs)) - (branch-weight (right-branch bs))))))) (+ (branch-weight (left-branch mobile)) (branch-weight (right-branch mobile)))) -- cgit v1.2.3