Code/Notes |
Sp |
# |
Utterance |
Hail.prb
|
T |
5 |
When you've finished reading the last page a "done" button will appear. Just click it to get started. |
|
T |
7 |
First we'll do an example. |
|
T |
9 |
Let's start with 12. Can you tell me what comes next? |
|
S |
10 |
6 |
|
T |
11 |
right. After that? |
|
S |
12 |
3 |
|
T |
13 |
good. next? |
|
S |
14 |
10 |
|
T |
15 |
yep. Go ahead and list the rest. |
|
S |
16 |
5 |
|
S |
17 |
16 |
|
S |
18 |
8 |
|
S |
19 |
4 |
|
S |
20 |
2 |
|
S |
21 |
1 |
|
T |
22 |
good. |
|
T |
23 |
any reason to do more? |
|
S |
24 |
That should be the ground state. |
|
T |
25 |
right on. Can you tell me know many items are in the sequence? |
|
S |
26 |
9 |
|
T |
27 |
close... we should start counting with the 12 and end with the 4 including both of them in the count. |
|
S |
28 |
I forgot the twelve so you count the 2 and the 1? |
|
T |
29 |
for this program we'll just stop the counting at 4 although there is no important reason to not include 1 and 2 we'll just go that route. |
|
T |
30 |
so how many elements from 12 down to 4 were there? |
|
S |
31 |
8 |
|
T |
32 |
excellent. And what was the largest value in the sequence? |
|
S |
33 |
16 |
|
T |
34 |
you got it. |
|
T |
35 |
Let's start writing some pseudo-code. Your job is to come up with the steps of the program. |
|
T |
36 |
Can you tell me the first thing it will need to do? |
|
S |
37 |
to get an integer from the user |
|
S |
38 |
Are we skiiping the normal steps like var section and begin etc. |
|
T |
39 |
good. |
|
T |
40 |
yeah pseudo-code is totally open ended ignore programming language specifics like that. |
|
T |
41 |
where should we store this integer? |
|
S |
42 |
in a variable say (first number). |
|
T |
43 |
can you come up with a different name? |
|
T |
44 |
We'll use the variable for more than the first. |
|
S |
45 |
initial val. |
|
T |
46 |
Well it's ok to do this but it will cause us more work shortly. Let's just call it HailNumber. Sound ok? |
|
S |
47 |
yep! |
|
T |
48 |
(tile created) get an integer from the user stored in HailNumber |
|
T |
50 |
go ahead and drag that up. |
|
S |
51 |
(tile placed) |
|
T |
52 |
you might want to leave a little space to the left and up just for breathing room later. |
|
S |
54 |
(tile placed) |
|
T |
55 |
that's plenty. Good. |
|
T |
56 |
Ok what next? |
|
S |
57 |
determine if the integer is positive or negative. |
|
T |
58 |
we can put off error checking for now... |
|
S |
59 |
I mean even or odd. |
|
T |
60 |
ah! |
|
T |
61 |
which one first? |
|
S |
62 |
even |
|
T |
63 |
ok. Can you phrase it as an "if"? |
|
S |
64 |
if hailstone mod 2 equals 0. |
|
T |
65 |
that's fine but too detailed for pseudo-code really. |
|
T |
66 |
Also we are checking a specific variable that we have in our program so far. |
|
T |
67 |
wanna try again? |
|
S |
68 |
if hailstone is even then double it. |
|
S |
69 |
I mean divide by two |
|
T |
70 |
I think we called the variable HailNumber. |
|
T |
71 |
but we could have used hailstone it really didn't matter. |
|
S |
72 |
we did |
|
T |
73 |
(tile created) if HailNumber is even |
|
S |
75 |
(tile placed) |
|
T |
76 |
you might want to bring that up a line or else our whole program will take up too much space. |
|
S |
78 |
(tile placed) |
|
T |
79 |
looks good. |
|
T |
80 |
(tile created) divide HailNumber by 2 |
|
S |
82 |
(tile placed) |
|
T |
83 |
usually the body of an if is indented so show the structure better. Can you do that? |
|
S |
85 |
(tile placed) |
|
T |
86 |
looks good. |
|
T |
87 |
ok what do we need to do next? |
|
S |
88 |
else if hailnumber is odd multiply by 3 and add 1. |
|
T |
89 |
good. |
|
T |
90 |
to simplify if it turns out the number was not even then what do we know for sure? |
|
S |
91 |
it is odd. |
|
T |
92 |
good so we just need "else". |
|
T |
93 |
(tile created) else |
|
S |
95 |
(tile placed) |
|
T |
96 |
and then what happens? |
|
S |
97 |
multiply by three and add 1. |
|
T |
98 |
multiply what by 3? |
|
S |
99 |
hailnumber |
|
T |
100 |
good. ALthough it is obvious here we need to be careful about variables in pseudo-code. |
|
T |
102 |
(tile created) multiply HailNumber by 3 and add 1 |
|
S |
104 |
(tile placed) |
|
T |
105 |
looks good so far. |
|
T |
108 |
what do we need to work on next? |
|
S |
109 |
Finding the how many numbers are in the sequence. |
|
T |
111 |
are you sure? |
|
T |
112 |
does our program generate an entire sequence? |
|
S |
113 |
We need to see if the new number is now odd or positive. |
|
T |
114 |
right... and after we do that are we done? |
|
S |
115 |
Not unless we reach the ground state. |
|
T |
116 |
how can that be determined in the program? |
|
S |
117 |
by a loop |
|
T |
118 |
right! |
|
T |
119 |
So we need to set up a loop somehow. |
|
T |
120 |
Any idea on what the loop condition should be? |
|
S |
121 |
do we need a new variable to store the modified hailnumber? |
|
T |
122 |
perhaps... but how many variables would that require? |
|
S |
123 |
I guess that depends on the hailnumber and if that means that there could be a ton of them |
|
T |
124 |
right. So rather than create a new variable for every possible situation can you think of another way? |
|
S |
125 |
a procedure that allows us to change the variable hailnumber. |
|
T |
126 |
maybe somehow but there is an even easier way. Let's just reuse HailNumber. |
|
T |
127 |
so we should modify those inner tiles to specify the destination of the action. |
|
S |
128 |
So in other words we just keep readln the new number. |
|
T |
129 |
not quite we'll read in the initial value then calculate every subsequent value using the code you've written. |
|
S |
130 |
ok |
|
T |
131 |
Here put this to the right of the "divide" tile. |
|
T |
132 |
(tile created) store in HailNumber |
|
S |
134 |
(tile placed) |
|
T |
135 |
same deal but with the multiply. |
|
T |
136 |
(tile created) store in HailNumber |
|
S |
138 |
(tile placed) |
|
T |
155 |
now that HailNumber is changing can you tell me when our loop will stop? |
|
S |
157 |
(tile placed) |
|
S |
162 |
It will stop when hailnumber gets to the ground state 4 2 1. |
|
T |
163 |
good. so do we loop while what is true? |
|
S |
164 |
while hailnumber does not equal four. |
|
T |
165 |
excellent. that is the start of the loop. Good job! |
|
T |
166 |
(tile created) while hailnumber does not equal four. |
|
S |
168 |
(tile placed) |
|
T |
169 |
think about that what are we going to need to do inside the loop? |
|
S |
170 |
either divide the number or multiply it. |
|
T |
171 |
right. And we already have code for that in our program. |
|
T |
172 |
So... would you like to move that while tile to take advantage of that fact? |
|
S |
174 |
(tile placed) |
|
T |
194 |
remember you can draw a big box around the tiles and move them togther. |
|
S |
200 |
(tile placed) |
|
T |
214 |
you're getting there... |
|
S |
216 |
(tile placed) |
|
T |
236 |
everything in the loop should be indented too. |
|
T |
238 |
actually that if should go back to before the divide... none of that needs to change from before. |
|
S |
239 |
(tile placed) |
|
T |
286 |
very nice. |
|
T |
287 |
to be complete here's an end marker for the loop. |
|
T |
288 |
(tile created) end while loop |
|
S |
290 |
(tile placed) |
|
T |
292 |
alright. This looks good. |
|
T |
293 |
We'll stop and take a snapshot now... but we need to give it a title. |
|
T |
294 |
Can you summarize (in a couple of words) what this code does? |
|
T |
295 |
don't click the snapshot button yet. |
|
S |
296 |
Is hailstone odd or even and what is the number. |
|
T |
297 |
sure... but even more general. This program generates a hailstone sequence. |
|
S |
298 |
So lets call it hailstone sequence or just hailstone. |
|
T |
299 |
for a snapshot description you want to describe what the program does. So you could say "create a hailstone sequence" or something close to that. |
|
T |
300 |
Go ahead and do that... type it into the description box and click "take a snapshot". |
|
T |
304 |
awesome. If you click on "stage 2" we can go back to work. |
|
T |
305 |
ok what should we do next? |
|
S |
306 |
Do we need to know how many numbers are in the sequence? |
|
T |
307 |
sounds good. |
|
T |
308 |
we'll need a variable to hold that can you suggest a good name? |
|
S |
309 |
sequenceamount |
|
T |
310 |
amount is a little vague I think. It is holding a counter.... can you try again? |
|
S |
311 |
sequencetotal |
|
S |
312 |
Now that sounds like it is adding up the numbers uh? |
|
T |
313 |
I hate to be picky here but yeah it does. |
|
T |
314 |
How about something really direct. It is a variable that holds a count of the items so how about "count"? |
|
T |
315 |
or "counter"? |
|
S |
316 |
sounds good. |
|
T |
317 |
great. So how can we use it to keep the count? |
|
S |
318 |
Each time that the loop is done a number can be stored in the counter var |
|
T |
319 |
so what do we need to do to counter in the loop? |
|
T |
320 |
each time through the loop how many hailstone values have we calculated? |
|
S |
321 |
initailize it at zero. |
|
T |
322 |
absoutely we'll initialize it to something. How about inside the loop. |
|
S |
323 |
Next counter plus 1. |
|
T |
324 |
Good. Each iteration of the loop represents a new hailstone value. |
|
T |
325 |
How many does that add to the count? |
|
S |
326 |
Just one. |
|
T |
327 |
bingo! |
|
T |
328 |
adding one to a variable has a name. Do you know it? |
|
S |
329 |
I can't remember you just said it today too! |
|
T |
330 |
it's called "incrementing" a variable. |
|
T |
331 |
so here's a tile for that. You may need to move something around to fit it in. |
|
T |
332 |
(tile created) increment counter |
|
S |
334 |
(tile placed) |
|
T |
341 |
very nice. |
|
S |
344 |
(tile placed) |
|
T |
345 |
ok so you suggested we intiialize counter to 0. |
|
T |
347 |
so does that mean we do or do not include the user value in the sequence? |
|
S |
348 |
We need to include it so we should initialize at one. |
|
T |
349 |
good. |
|
T |
350 |
(tile created) initialize counter to 1 |
|
S |
358 |
(tile placed) |
|
T |
450 |
hold up a sec.... |
|
S |
451 |
(tile placed) |
|
T |
480 |
so you want to re-initilize the counter every time in the loop? |
|
S |
481 |
(tile placed) |
|
S |
483 |
No |
|
T |
485 |
So you might want to swap the locations of the while and intiialize tiles |
|
S |
487 |
(tile placed) |
|
T |
581 |
looks good... one little thing. |
|
T |
582 |
the get tile and the initialize tile happen one after another so they should be lined up along the left. |
|
T |
583 |
I'll do it for you.... |
|
T |
585 |
(tile placed) |
|
S |
587 |
Thanks!! |
|
T |
588 |
We've got one minor thing left to do with the counter then. |
|
S |
589 |
Stop it when it gets to four. |
|
T |
590 |
actually the counter will probably go much higher than 4. |
|
T |
591 |
which is ok. |
|
T |
592 |
Our example sequence earlier had 8 items remember? |
|
S |
593 |
Yes! |
|
T |
595 |
thus far we've done the counting correctly. We just need to inform the user of the result. |
|
S |
596 |
Writeln counter |
|
T |
597 |
in other words print it. good. |
|
T |
598 |
(tile created) print counter |
|
S |
600 |
(tile placed) |
|
T |
601 |
perfect. |
|
T |
603 |
ok... so tell me in a few words we just added code to do what? |
|
S |
604 |
Add total of items. |
|
T |
605 |
not really a total which implies addition or summation but a count of the items. |
|
T |
606 |
So type something like "count hailstone sequences" as a description and take the snapshot. |
|
T |
610 |
very good! |
|
T |
611 |
So what should we work on next? |
|
S |
612 |
Figuring out the largest number in the sequence. |
|
T |
613 |
good. we'll need a variable to hold that value. Any suggestions? |
|
S |
614 |
largestnumber |
|
T |
615 |
great. What should we initialize it to? |
|
S |
616 |
to zero |
|
T |
617 |
that could work... |
|
T |
618 |
any other possibilities come to mind? |
|
S |
619 |
Maybe to the original hailnumber would that work? |
|
T |
620 |
very good idea. |
|
T |
621 |
Think of the example 16 8 4 |
|
T |
622 |
the first value was the largest for that case. |
|
T |
623 |
here's the tile. you can just nude the "get" tile up a bit to make room. |
|
T |
624 |
(tile created) initialize LargestNumber to HailNumber |
|
S |
626 |
(tile placed) |
|
T |
638 |
Essentially we are assuming the first is the largest. Then we'll need to go find out if any larger ones ever come up. |
|
T |
639 |
how can we do that? |
|
S |
640 |
if statement |
|
T |
641 |
good. We'll compare what with what? |
|
S |
642 |
hailnumber to hailnumber |
|
T |
643 |
Are you sure? |
|
T |
644 |
we'll defintely consider each hail number absolutely. |
|
S |
645 |
largest number to the other hailnumbers besides the first one entered by the user. |
|
T |
646 |
closer... think inside the loop. We have HailNumber which is the current hailstone value. |
|
T |
647 |
We also have the Largest one so far. |
|
T |
648 |
Let's go back to the example we did. Starting with 12. |
|
T |
649 |
We say 12 is the largest. |
|
T |
650 |
Ok what is after 12? |
|
S |
651 |
6 |
|
T |
652 |
what is the largest? |
|
S |
653 |
12 |
|
T |
654 |
why isn't 6 the largest? |
|
S |
655 |
It is smaller then 12. |
|
T |
656 |
ok after 6? |
|
S |
657 |
3 |
|
T |
658 |
largest? |
|
S |
659 |
6 |
|
S |
660 |
12 |
|
T |
661 |
really? |
|
T |
662 |
good. 12 remains the largest. We haven't found one larger yet. |
|
T |
663 |
After 3? |
|
S |
664 |
10 |
|
T |
665 |
12 holds up still. |
|
T |
666 |
next? |
|
S |
667 |
5 |
|
T |
668 |
after that? |
|
S |
669 |
16 |
|
T |
670 |
so what happens to LargestNumber now? |
|
S |
671 |
It is now 16. |
|
T |
672 |
what two numbers did you compare to figure that out? |
|
S |
673 |
16 and 12 |
|
T |
674 |
good. Generalizing you compared the LargestNumber to HailNumber. |
|
T |
675 |
so can you put it together for an if tile for use in the loop? |
|
T |
676 |
you need to compare HailNumber to LargesNumber. |
|
T |
677 |
HailNumber holds the current hailstone value. LargestNumber holds the largest one you know about so far. |
|
T |
678 |
here you go. We need to see if HailNumber is bigger than LargestNumber. |
|
T |
679 |
(tile created) if HailNumber > LargestNumber then |
|
T |
680 |
that will need to go in the loop. |
|
S |
683 |
(tile placed) |
|
T |
701 |
hold up on that! We need space for the body of the if. |
|
S |
704 |
(tile placed) |
|
T |
712 |
good. the end should stay lined up with the while. |
|
T |
713 |
Also we only indent when we have a body of another statement. |
|
S |
715 |
(tile placed) |
|
T |
719 |
the newest if tile is only a part of the while and not the increment. |
|
S |
720 |
(tile placed) |
|
T |
729 |
it should line up with the increment really. it is part of the loop. |
|
S |
731 |
(tile placed) |
|
T |
733 |
great! Sorry to be so picky. |
|
T |
734 |
ok.... we're almost done. |
|
T |
735 |
so if that condition turns out to be true what does that mean? |
|
S |
736 |
need to print the new largest number. |
|
T |
737 |
eventually yes. But not in the loop. We'd be printing out lots of largest values if we did that. |
|
T |
738 |
you said it right though. We have a new largest value when that is true. |
|
T |
739 |
thus we need to remember that new largest value. |
|
T |
740 |
remember in the example when you thought 12 was the largest but then we found 16? |
|
S |
741 |
Yep |
|
T |
742 |
so in your head you erased 12 and put 16 there. |
|
S |
743 |
Correct |
|
T |
744 |
so in the program if that condition is true we've found a new largestNumber. |
|
S |
745 |
Yes so we need to readln or remember that number. |
|
T |
746 |
even simpler. We only readln to get things started at the beginning. |
|
T |
747 |
LargestNumber holds the largest so far. |
|
T |
748 |
So if we've found a new largest we need to update that variable. |
|
T |
749 |
so tell me what do we assign to LargestNumber inside that if? |
|
S |
750 |
Then hailnumber equals largest number |
|
T |
751 |
other way around! |
|
S |
752 |
oh |
|
S |
753 |
I see! |
|
T |
754 |
we need to remember that the current hailvalue is now the largest. |
|
T |
755 |
Good job! |
|
T |
756 |
(tile created) LargesteNumber is assigned HailNumber |
|
T |
758 |
typo on that one. sorry. |
|
S |
759 |
(tile placed) |
|
T |
760 |
then we print it out. |
|
T |
761 |
(tile created) print LargestNumber |
|
T |
763 |
good. |
|
S |
764 |
(tile placed) |
|
T |
765 |
AFTER the loop is done. |
|
S |
767 |
(tile placed) |
|
T |
774 |
see how LargestNumber will only change when you've found a new largest? |
|
S |
775 |
YEs |
|
T |
776 |
let's take a final snapshot then we're done. |
|
T |
777 |
I'd say this program keeps track of the largest. |
|
T |
778 |
could you go ahead and do that? |
|
S |
779 |
Hailstone's largest sequence |
|
T |
780 |
Sure... something about "finding the largest in the sequence" would be good. |
|
T |
781 |
you go ahead and type it in and then we're done! |