Day20: 2 & 3

0 views
Skip to first unread message

Joe Larson

unread,
Jun 15, 2011, 4:22:38 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
I don't know if I'm doing the store tracking right. My program works
and all my tests pass, so is the following format okay for store
tracking in the defense:

// Store Tracking for translateAllNoNew(arrayOfPosn, 10, 10 );
// Start : arrayOfPosn = Posn[] { (0,10), (1,11), (2,12), (3,13),
(4,14) };
// Loop 1 ( i = 0 )
arrayOfPosn = Posn[] { new Posn (10,20), (1,11), (2,12), (3,13),
(4,14) };
// Loop 2 ( i = 1 )
arrayOfPosn = Posn[] { (10,20), new Posn (11,21), (2,12), (3,13),
(4,14) };
// Loop 3 ( i = 2 )
arrayOfPosn = Posn[] { (10,20), (11,21), new Posn (12,22), (3,13),
(4,14) };
// Loop 4 ( i = 3 )
arrayOfPosn = Posn[] { (10,20), (11,21), (12,22), new Posn (13,23),
(4,14) };
// Loop 5 ( i = 4 )
arrayOfPosn = Posn[] { (10,20), (11,21), (12,22), (13,23), new Posn
(14,24) };
[End of for loop]

Jay McCarthy

unread,
Jun 15, 2011, 4:25:11 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
That's half to what I'd like. It would be better if it was like...

/*
p1 = Posn( 0, 0 )
...
ps = Posn[] { p1, p2, p3 ... }
*/

so you can distinguish between when ps changes and when pi changes

Jay

2011/6/15 Joe Larson <brothe...@gmail.com>:

--
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

Joe Larson

unread,
Jun 15, 2011, 4:35:30 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
so just put the Posn names and values at the top and then like this
for #2:
arrayOfPosn = Posn[] { new Posn (10,20), p2, p3, p4, p5 };

and like this for #3:

arrayOfPosn = Posn[] { p1 = (10,20), p2, p3, p4, p5 };

does that format look okay? And we just write it our in our defense
right?

On Jun 15, 2:25 pm, Jay McCarthy <jay.mccar...@gmail.com> wrote:
> That's half to what I'd like. It would be better if it was like...
>
> /*
>  p1 = Posn( 0, 0 )
>  ...
>  ps = Posn[] { p1, p2, p3 ... }
> */
>
> so you can distinguish between when ps changes and when pi changes
>
> Jay
>
> 2011/6/15 Joe Larson <brotherjos...@gmail.com>:
>
>
>
>
>
>
>
>
>
> > I don't know if I'm doing the store tracking right. My program works
> > and all my tests pass, so is the following format okay for store
> > tracking in the defense:
>
> > // Store Tracking for translateAllNoNew(arrayOfPosn, 10, 10 );
> > // Start : arrayOfPosn = Posn[] { (0,10), (1,11), (2,12), (3,13),
> > (4,14) };
> > // Loop 1 ( i = 0 )
> > arrayOfPosn = Posn[] { new Posn (10,20), (1,11), (2,12), (3,13),
> > (4,14) };
> > // Loop 2 ( i = 1 )
> > arrayOfPosn = Posn[] { (10,20), new Posn (11,21), (2,12), (3,13),
> > (4,14) };
> > // Loop 3 ( i = 2 )
> > arrayOfPosn = Posn[] { (10,20), (11,21), new Posn (12,22), (3,13),
> > (4,14) };
> > // Loop 4 ( i = 3 )
> > arrayOfPosn = Posn[] { (10,20), (11,21), (12,22), new Posn (13,23),
> > (4,14) };
> > // Loop 5 ( i = 4 )
> > arrayOfPosn = Posn[] { (10,20), (11,21), (12,22), (13,23), new Posn
> > (14,24) };
> > [End of for loop]
>
> --
> Jay McCarthy <j...@cs.byu.edu>
> Assistant Professor / Brigham Young Universityhttp://faculty.cs.byu.edu/~jay

Joe Larson

unread,
Jun 15, 2011, 4:37:44 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
I mean #1 and #2... sorry... I even named the post wrong

Jay McCarthy

unread,
Jun 15, 2011, 4:49:46 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
2011/6/15 Joe Larson <brothe...@gmail.com>:

> so just put the Posn names and values at the top and then like this
> for #2:
> arrayOfPosn = Posn[] { new Posn (10,20), p2, p3, p4, p5 };
>
> and like this for #3:
>
> arrayOfPosn = Posn[] { p1 = (10,20), p2, p3, p4, p5 };
>
> does that format look okay? And we just write it our in our defense
> right?

Not exactly...

Here's one for #1

// Step 0
p0 = (0,0)
ps = [ p0 ]
// Step 1
p0 = (0,0)
p0' = (10,10)
ps = [ p0' ]

Here's one for #2

// Step 0
p0 = (0,0)
ps = [ p0 ]
// Step 1
p0 = (10,10)
ps = [ p0 ]

Jay

Joe Larson

unread,
Jun 15, 2011, 4:57:17 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
So if I understand you right, this is this okay, right:

// Store Tracking
// Start
zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
(4,14);
arrayOfPosn = Posn[] { zero, one, two, three, four };

// Loop 1 ( i = 0 )
zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
(4,14);
arrayOfPosn = Posn[] { new Posn (10,20), one, two, three, four };

// Loop 2 ( i = 1 )
zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
(4,14);
arrayOfPosn = Posn[] { new Posn (10,20), new Posn (11,21), (2,12),
(3,13), (4,14) };
.....etc...



On Jun 15, 2:49 pm, Jay McCarthy <jay.mccar...@gmail.com> wrote:
> 2011/6/15 Joe Larson <brotherjos...@gmail.com>:

Joe Larson

unread,
Jun 15, 2011, 5:01:10 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
I don't know if I understand what "p0" and "ps" and "[ p0 ]" mean in
your example.

Jay McCarthy

unread,
Jun 15, 2011, 5:03:34 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
2011/6/15 Joe Larson <brothe...@gmail.com>:

> So if I understand you right, this is this okay, right:
>
> // Store Tracking
> // Start
> zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
> (4,14);
> arrayOfPosn = Posn[] { zero, one, two, three, four };
>
> // Loop 1 ( i = 0 )
> zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
> (4,14);
> arrayOfPosn = Posn[] { new Posn (10,20), one, two, three, four };

This is wrong because "new Posn (10,20)" is not the name of a posn,
like "zero", "one" and "two" are. Give that new posn a name and the
array should have that in it.

Jay

Joe Larson

unread,
Jun 15, 2011, 5:25:07 PM6/15/11
to BYU CS 142 (Spring 2011) [McCarthy]
For ex1, when i write: "arrayOfPosn = Posn[] { new Posn (10,20), one,
two, three, four };" I'm writing what's happening in my function. Did
I do the exercise wrong? Because in my function I'm assigning a new
Posn() to arrayOfPosn[(some index)], not to a variable name (like one,
two, three). do I need to write it like this maybe: arrayOfPosn[0] =
new Posn(10, 20);

I'm supposed to create new Posns for ex1 right? then change it to
mutate for ex2 right?

Lucas Amorim

unread,
Jun 15, 2011, 6:36:16 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
I'm also very confused with how we should do the store tracking. I was told by a TA that just showing the store tracking for each element of the array would be fine as opposed to running through all the calculation....
Could I ask for a template or something of the like?

Thanks.

Jay McCarthy

unread,
Jun 15, 2011, 11:16:02 PM6/15/11
to byu-cs-jm-14...@googlegroups.com
2011/6/15 Joe Larson <brothe...@gmail.com>:

> For ex1, when i write: "arrayOfPosn = Posn[] { new Posn (10,20), one,
> two, three, four };" I'm writing what's happening in my function. Did
> I do the exercise wrong? Because in my function I'm assigning a new
> Posn() to arrayOfPosn[(some index)], not to a variable name (like one,
> two, three). do I need to write it like this maybe: arrayOfPosn[0] =
> new Posn(10, 20);

The problem with writing "new Posn" anywhere is that it isn't clear
that it ISN'T a new posn. It's the same old posn with new values
inside.

>
> I'm supposed to create new Posns for ex1 right? then change it to
> mutate for ex2 right?

Correct

Jay McCarthy

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

> I'm also very confused with how we should do the store tracking. I was told by a TA that just showing the store tracking for each element of the array would be fine as opposed to running through all the calculation....

That is an accurate statement

> Could I ask for a template or something of the like?

I have sent three templates.

Jay

Joe Larson

unread,
Jun 16, 2011, 12:00:26 AM6/16/11
to BYU CS 142 (Spring 2011) [McCarthy]
I'm sorry, I still don't understand the templates ( "p0", "ps",
"[ p0 ]"??). What do I write to represent the new Pons created in ex1?
(See below)

// Step 1
zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
(4,14);
arrayOfPosn = Posn[] { new Posn (10,20), one, two, three, four };

Posn zero is still equal to (1, 10), but the array now has a Posn with
coordinates (10,20) which is only assign to arrayOfPosn[0], not its
own variable like zero, one, etc. So how do you want me to represent
it.

Jay McCarthy

unread,
Jun 16, 2011, 7:30:13 AM6/16/11
to byu-cs-jm-14...@googlegroups.com
2011/6/16 Joe Larson <brothe...@gmail.com>:

> I'm sorry, I still don't understand the templates (  "p0", "ps",
> "[ p0 ]"??). What do I write to represent the new Pons created in ex1?
> (See below)
>
> // Step 1
> zero = (0,10); one = (1,11); two = (2,12); three = (3,13); four =
> (4,14);
> arrayOfPosn = Posn[] { new Posn (10,20), one, two, three, four };
>
> Posn zero is still equal to (1, 10), but the array now has a Posn with
> coordinates (10,20) which is only assign to arrayOfPosn[0], not its
> own variable like zero, one, etc. So how do you want me to represent
> it.

Pretend that there is a variable for it. That's what p0' was.

Jay

Reply all
Reply to author
Forward
0 new messages