alice-teacher A number list is being filled with booleans

Carlos Bovell cbovell at nburlington.com
Tue Jan 25 14:46:45 EST 2022


Hi,

Thanks for your response. In the example I worked out together with one of my students we started with the number variable set equal to 129.

The student begins with a list containing the numbers 20, 10, 5 and 1.
Using an "all in order" loop:
We divided 129 by the 20 from a list we made. We got 6 after converting to an int. We used the add to the end of the list assignment operator to make 6 the first value of a second, empty list.
Then we subtracted 20 * 6 from 129 and replaced the old value of 129 with the new value of 9.
Next, we divided 9 by 10 and got 0, but instead of Alice adding 0 to the list, it added false!
Next, we subtracted 10 * 0 from 9 to get the "updated" value of 9 (which is the same value that would have been there from the last round).
Then we divided 9 by 5 and got 1 (as an int), but instead of Alice adding 1 to the list, it added true!

This is what we were wondering about: Is this an error on our part or is it an Alice bug?

I'll take your suggestion and try filling the Alice list with zeros, but the thing with a list is that we should be able to use it when we don't know how big it's going to get. If we want to set aside an arbitrary number of slots, I think an array in java is filled with zeros before it's initialized by a programmer -- we can do this because we're saying in advance how big to make it --  but I thought an ArrayList (again, going but what I think happens in java) would be empty and the add() method is used to add to the end of the list, one at a time, using each value to initialize the list, one element at a time, growing the size of the list. With an ArrayList, there is no reason to distinguish between logical size and actual size.

Thanks for taking the time to try to help clarify what is going on in our program.

Carlos
________________________________
From: alice-teachers <alice-teachers-bounces+cbovell=nburlington.com at lists.andrew.cmu.edu> on behalf of Donald Slater via alice-teachers <alice-teachers at lists.andrew.cmu.edu>
Sent: Tuesday, January 25, 2022 2:04 PM
To: Alice Teachers <alice-teachers at lists.andrew.cmu.edu>
Subject: Re: alice-teacher A number list is being filled with booleans

CAUTION:  This is email originated from outside of the organization.  Please exercise caution when clicking links, opening attachments, or providing personal information.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.andrew.cmu.edu/pipermail/alice-teachers/attachments/20220125/87daf17b/attachment-0001.html>


More information about the alice-teachers mailing list