Ex3?

0 views
Skip to first unread message

Lucas Amorim

unread,
Jun 8, 2011, 1:11:05 AM6/8/11
to BYU CS 142 (Spring 2011) [McCarthy]
I'm at a loss here:

return this.first + 10 * this.rest.to10(currentNum) ;

How can I change this to accumulator style?

Streber

unread,
Jun 8, 2011, 2:14:15 AM6/8/11
to BYU CS 142 (Spring 2011) [McCarthy]
You have all the correct pieces there, you just need to move the
actual calculation inside of the function (i.e. the calculation should
take place inside of the parentheses of to10( *argument* )). It's hard
to say more without giving the whole thing away, but you are really
close. Here's a hint: this.rest, being a list, does NOT belong inside
of the function, since the function takes only integers as arguments.
However, this.first is an integer, so it can be moved inside the
function.

Lucas Amorim

unread,
Jun 9, 2011, 11:50:34 AM6/9/11
to BYU CS 142 (Spring 2011) [McCarthy]
Is it OK if we return an int that is one character off?

Mine keeps returning 1822 instead of 1821...

(Maybe the letter count tool I'm using is a little off?...)

Blake Johnson

unread,
Jun 9, 2011, 5:05:24 PM6/9/11
to byu-cs-jm-14...@googlegroups.com
You might not be counting the last character. I can't tell for sure without looking at your code, obviously.

Blake

Blake Johnson

unread,
Jun 9, 2011, 5:07:02 PM6/9/11
to byu-cs-jm-14...@googlegroups.com
Sorry, I read yours backwards, if yours is one too big, I'm not sure what it might be, but you should try to get the right answer (maybe test with a file that only has 5 characters or something).

Blake

Lucas Amorim

unread,
Jun 9, 2011, 5:33:31 PM6/9/11
to byu-cs-jm-14...@googlegroups.com
Thanks, I think I solved it.

Fox Philip

unread,
Jun 9, 2011, 7:22:14 PM6/9/11
to byu-cs-jm-14...@googlegroups.com
We are basically counting the characters, right? Or are we only counting the letters, which would mean not the spaces in between the letters?  Because characters are both spaces and letters right?

Diego (TA)

unread,
Jun 9, 2011, 7:52:33 PM6/9/11
to byu-cs-jm-14...@googlegroups.com, byu-cs-jm-14...@googlegroups.com
You want to count everything, letters, spaces and new lines (\n and \r).
Have fun!

Lucas Amorim

unread,
Jun 15, 2011, 6:49:18 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
I'm not exactly sure what this exercise is asking for us to do...

So we create a function that updates the key of a node. Updates it to
what? To a Japanese equivalent number? I'm not sure.

Thanks.

Jay McCarthy

unread,
Jun 15, 2011, 11:18:29 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
2011/6/15 Lucas Amorim <amor...@gmail.com>:

> I'm not exactly sure what this exercise is asking for us to do...
>
> So we create a function that updates the key of a node. Updates it to
> what? To a Japanese equivalent number? I'm not sure.

"Write a function call 'update' which takes a BST, a key, and a string
and returns a BST where the key's value has been updated. Do not use
mutation."

You must write a function named update. It will take three arguments:
tree, key, and newValue. It should return a new tree where the key
gets mapped to newValue. How could I write the instructions any
differently?

Separately, you must answer the question:

"What is the fewest number of new nodes that must be created to update
the tree so that 15 is mapped to "Fifteen" rather than "十五"?"

Jay

>
> Thanks.

--
Jay McCarthy <j...@cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Lucas Amorim

unread,
Jun 16, 2011, 8:33:04 AM6/16/11
to byu-cs-jm-14...@googlegroups.com
Ok, I think I got the question now.

So we update the Japanese String values to their English equivalent?

I still don't really get the separate question... Is there a limit to the number of nodes you have before you can update the tree?

Jay McCarthy

unread,
Jun 16, 2011, 9:00:24 AM6/16/11
to byu-cs-jm-14...@googlegroups.com
2011/6/16 Lucas Amorim <amor...@gmail.com>:

> Ok, I think I got the question now.
>
> So we update the Japanese String values to their English equivalent?

No. You write a function that can update any key to any value.

>
> I still don't really get the separate question... Is there a limit to the number of nodes you have before you can update the tree?

I don't know what this means.

Reply all
Reply to author
Forward
0 new messages