Comments (3)
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-57You can also see my test case, again highlighted with the relevant test:
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.
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-57You can also see my test case, again highlighted with the relevant test:
Again, it is this test case which I submit should be changed to accept
'bar.Regards,
Christian RomneyReply to this email directly or view it on GitHubhttps://github.com//issues/10
.
from eopl3.
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)
- A type error in example code ? HOT 2
- fact/k registerized has wrong fact1-cont? HOT 2
- exercise 2.20 (page 45) minor fix HOT 1
- exercise 7.28 example code HOT 1
- Some unmatched parentheses HOT 1
- CPS transformer from chapter 6 doesnβt handle variable scope correctly HOT 2
- Incorrect code sample in exercise 7.28 HOT 2
- Errata for Page 303 HOT 3
- Errata for Page 341 and 362 HOT 2
- Errata for Page 180 HOT 1
- MIT page link broken HOT 2
- SLLGEN cannot report error when input string is illegal. HOT 1
- Don't know how to setup HOT 1
- There's no pack in exercise 3.18
- The specifications for deref-exp and setref-exp are not quite correct HOT 1
- Maybe an erratum on page 116 HOT 1
- A question, how could I implement while and for similar to those of java in this interpreter?
- An erratum on page 226
- Errata for Exercise 2.19 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eopl3.