Git Product home page Git Product logo

Comments (3)

mwand avatar mwand commented on September 24, 2024

Thanks. I'm travelling now; I will look into this when I get back.

Dan, would you like to weigh in on this in the meantime?

--Mitch

On Sat, Jan 25, 2014 at 12:39 PM, Christian Romney <[email protected]

wrote:

Hi Mitch,

I think I may have found another erratum in exercise 2.25 on page 50. The
exercise for max-interior gives some test cases. The last of these is

(max-interior tree-3) ;; => baz

and goes on to say that 'foo is also acceptable as an answer. However,
would 'bar not be an acceptable answer? In fact, I submit that it is a
better answer than 'baz since that is the key assigned to the
interior-node that is the root node in this case, tree-3. In which
case, it tells us nothing since either the left child (interior-node bar)
and right child (leaf-node 1) might have the greater sum.

Sorry if that's a bit tough to follow. In short, I believe the correct
answer should be 'bar and not 'baz for this exercise, while _'foo_remains valid.

Here (only) you can see my implementation where I've highlighted the
relevant cond clause:
https://github.com/christianromney/eopl3/blob/9c6be1f609492449fcd0fd5bffc8d89e12b8921a/src/ch02/bintree/datatype.rkt#L55-57

You can also see my test case, again highlighted with the relevant test:

https://github.com/christianromney/eopl3/blob/9c6be1f609492449fcd0fd5bffc8d89e12b8921a/test/ch02/bintree.rkt#L125-127

Again, it is this test case which I submit should be changed to accept
'bar.

Regards,
Christian Romney

β€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/10
.

from eopl3.

mwand avatar mwand commented on September 24, 2024

Dear Christian,

Perhaps you've misunderstood the problem. In tree-3, the leaf-sum of foo is
5, the leaf-sum of bar is 4, and the leaf-sum of bar is also 5. So either
bar or foo is correct, and bar is definitely wrong. My code is below
(using #lang racket, since that's easier for me than bringing #lang eopl
back into my memory.)

--Mitch

#lang racket

(struct leaf-node (num) #:transparent)
(struct interior-node (key left right) #:transparent)

(define tree-1
(interior-node 'foo (leaf-node 2) (leaf-node 3)))

(define tree-2
(interior-node 'bar (leaf-node -1) tree-1))

(define tree-3
(interior-node 'baz tree-2 (leaf-node 1)))

(define (leaf-sum t)
(cond
[(leaf-node? t) (leaf-node-num t)]
[else (+ (leaf-sum (interior-node-left t))
(leaf-sum (interior-node-right t)))]))

(map (lambda (t) (list (interior-node-key t) (leaf-sum t)))
(list tree-1 tree-2 tree-3))

Welcome to DrRacket, version 5.3.6 [3m].
Language: racket; memory limit: 256 MB.
'((foo 5) (bar 4) (baz 5))

On Sat, Jan 25, 2014 at 3:39 PM, Christian Romney
[email protected]:

Hi Mitch,

I think I may have found another erratum in exercise 2.25 on page 50. The
exercise for max-interior gives some test cases. The last of these is

(max-interior tree-3) ;; => baz

and goes on to say that 'foo is also acceptable as an answer. However,
would 'bar not be an acceptable answer? In fact, I submit that it is a
better answer than 'baz since that is the key assigned to the
interior-node that is the root node in this case, tree-3. In which
case, it tells us nothing since either the left child (interior-node bar)
and right child (leaf-node 1) might have the greater sum.

Sorry if that's a bit tough to follow. In short, I believe the correct
answer should be 'bar and not 'baz for this exercise, while _'foo_remains valid.

Here (only) you can see my implementation where I've highlighted the
relevant cond clause:
https://github.com/christianromney/eopl3/blob/9c6be1f609492449fcd0fd5bffc8d89e12b8921a/src/ch02/bintree/datatype.rkt#L55-57

You can also see my test case, again highlighted with the relevant test:

https://github.com/christianromney/eopl3/blob/9c6be1f609492449fcd0fd5bffc8d89e12b8921a/test/ch02/bintree.rkt#L125-127

Again, it is this test case which I submit should be changed to accept
'bar.

Regards,
Christian Romney

Reply to this email directly or view it on GitHubhttps://github.com//issues/10
.

from eopl3.

christianromney avatar christianromney commented on September 24, 2024

Hi Mitch,

Sorry to have wasted your time! I had, indeed, misunderstood the problem. Looking back at my code, I don't know how I had managed to convince myself only to consider interior nodes whose left and right children were both leaf nodes. Correcting that case instantly yielded the right answer. Thanks for your patience and for getting back to me so quickly.

from eopl3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.