'16-'17 General Discussion for Lesson 3.3


#1

Use this thread to discuss your questions and comments about how to run the lesson.


#2

FYI: Video: You Should Learn to Program: Christian Genco at TEDxSMU - Video is in both this lesson and U3L01.


#3

#4

In the Human Machine Language Part 2 Activity Guide, the example SWAP program seems to have an error in it. The program is supposed to reverse the order of the cards, according to the Lesson Plan. In order for it to do that, Line 5 should be changed to jump to line 2 instead of line 1. It should read:

5 JUMP TO LINE 2 IF (RHPos gt LHPos)


#5

I agree with your observation unless the goal was to create an infinite loop. I was send a note to the team. Thanks!
Andrea

Update: I looked at this again and it does end and it does complete a task in a round about way.


#6

Yikes. Good catch.

Fixed now to jump to line 2. Thanks!

Baker
CSP Team.


#7

Ha. I cannot remember now if that round about way was intentional or not. I’ve changed it to jump to line 2…which I think was my intent since it’s supposed to be a simple example.

Thanks though.

Baker


#8

It seems that there is an error in the second solution for Min to Front challenge.

By using a bubble sort method you are dragging some cards from right to left, but abandoning them in the middle of the line, when you find a lower card. Additionally, you never swap the lowest card to position zero. After you swap the lowest card to position 1, assuming position 0 is greater, you move your hands such that LH is on 0, you bypass the jump and stop.

Example:

Assuming Ace is low consider the following configuration:
9 5 6 8 A 4 3 2
LR
I will mirror the state and Line number to trace below:
1.
9 5 6 8 A 4 3 2
L__________R
2.
9 5 6 8 A 4 3 2
__________L R
3.
9 5 6 8 A 4 3 2
__________L R
4.
9 5 6 8 A 4 2 3
__________L R
5.
9 5 6 8 A 4 2 3
__________L
__________R
6.
9 5 6 8 A 4 2 3
________L R
7.
9 5 6 8 A 4 2 3
________L R
3.
9 5 6 8 A 4 2 3
________L R
4.
9 5 6 8 A 2 4 3
________L R
5.
9 5 6 8 A 2 4 3
________L
________R
6.
9 5 6 8 A 2 4 3
_______L R
7.
9 5 6 8 A 2 4 3
_______L R
3.
9 5 6 8 A 2 4 3
_______L R
5.
9 5 6 8 A 2 4 3
_______L
_______R
6.
9 5 6 8 A 2 4 3
_____L R
7.
9 5 6 8 A 2 4 3
_____L R
3.
9 5 6 8 A 2 4 3
_____L R
4.
9 5 6 A 8 2 4 3
_____L R
5.
9 5 6 A 8 2 4 3
_____L
_____R
6.
9 5 6 A 8 2 4 3
___L R
7.
9 5 6 A 8 2 4 3
___L R
3.
9 5 6 A 8 2 4 3
___L R
4.
9 5 A 6 8 2 4 3
___L R
5.
9 5 A 6 8 2 4 3
___L
___R
6.
9 5 A 6 8 2 4 3
__L R
7.
9 5 A 6 8 2 4 3
__L R
3.
9 5 A 6 8 2 4 3
__L R
4.
9 A 5 6 8 2 4 3
__L R
5.
9 A 5 6 8 2 4 3
__L
__R
6.
9 A 5 6 8 2 4 3
L R
7.
9 A 5 6 8 2 4 3
L R
8. (STOP)
9 A 5 6 8 2 4 3
L R

This is not equal to the correct configuration:
A 9 5 6 8 4 3 2

Trae Cooper


#9

@trae.cooper

I think you might be right… Perhaps Line 7 should check if RHPos gt 0…

Andrea


#10

Good catch. Abandoning cards in the middle is not a problem since we’re just trying to push the min card to the front.

But you’re both correct that the cards at positions 0,1 never get compared and therefore never get swapped if necessary.

I’d prefer not to switch the last line to: JUMP IF RHPos gt 0 because that would force the left hand to shift off the end of the list (phantom position -1) and we’ve never defined what happens when a hand goes off the list.

Instead I think we need to refactor the code to check if the LH is in position 0 after it has had a chance to swap.

Here’s my tentative solution. [edit – my temp solution crashed too. back to drawing board. I’ll figure it out]


#11

Thanks Baker, it looks like you fixed the final swap.

However with regard to not dragging cards along, it does matter. Here are the instructions for the challenge in the activity guide: (emphasis mine)

END STATE: When the program stops, the smallest card should be in position 0 and all other cards must be in their original relative ordering. The ending positions of the hands do not matter.

Kind Regards,
Trae


#12

mm. Yes. I see. Well I guess we should probably change the relative ordering rule :slight_smile:

Also, my previous solution (the fix) still crashed in the case that the cards in positions 0 and 1 did not need to be swapped. Fixing again…


#13

Yeah, I only traced it for once case. It worked on the basic case, but I didn’t try it on the case that you mentioned.

I only bring this up for the good of everyone, I don’t need a solution on a time crunch or anything. I am capable of tracing and assessing my students’ algorithms.

Kind Regards,
Trae


#14

Yes, but it’s fun to mess around isn’t it? Anyway, I should probably include what I think is the simplest solution:

[Keep left hand on card[0], shift right hand to the right swapping smaller cards into position 0 – this also does not abide by the “in-place” rule which I’m convinced I must lift. It must be the residue of an earlier version of the language.]

Check to see if this works…(I’m taking some liberties with the language for readability in text form)

1 JUMP to line 3 IF LHCard < RHCard
2 SWAP
3 JUMP to line 7 IF RHPos == 6
4 SHIFT RH to the R
5 JUMP to line 1
6 END

Bubble sort technique to come.


#15

It is fun to mess around :slight_smile:
I will say that i felt the rigor of the assignment was in the in-place rule. It is a much more sophisticated algorithm than simply building upon finding min, then swapping iteratively until you arrive at index 0

Either way, I’m not going to change the assignment for my students :wink:

This assignment reminds me of when I was learning assembler on the motorola 68k chip.


#16

I’ll take that to heart. Before I change anything I’m going to go back to my team to see if we can collectively remember if there was any reason we made the in-place rule. I hear you on the rigor of imposing the in-place rule but it’s more our style to make something like the in-place rule an optional challenge. Also, I worry a little bit that “rigor” here might just mean length of program.
It’s a tough to balance rigor with potential frustration from students/teachers when writing curriculum in the abstract. You are, of course, free to do what you like.

Anyway, i think this is the bubblesort solution

0 MOVE LH to pos 6
1 MOVE RH to pos 7
2 JUMP to Line 4 IF LHCard < RHCard
3 SWAP
4 JUMP to line 8 IF LHPos == 0
5 SHIFT LH to the L
6 SHIFT RH to the L
7 Jump to line 2
8 END


#17

The solution for Part 2: Min-to-Front here:

Referring to the left side 12 line solution. There appears to be a typo on line 6.
6. Jump to Line 3 should be
6. Jump to Line 2

Surprisingly, the incorrect solution (Jump to Line 3) does work correctly for a majority of the cases -
except for a few (about 10% of cases… avg of about 46 errors out of 500 samples) where the min card is in pos#7.


#18

I got tired of correcting the reams of homework for the Human Machine Language lessons. It’s really interesting but after 5 of them, I realize I won’t be able to finish. So I whipped up a HML simulator in Java. It simulates the input program written in HML text running over the cards, then examines the results for correctness. It will flag incorrect HML syntax, out-of-bounds references, etc and halts execution.

Can probably use a second pair of eyes to check for correctness. Let me know if interested. It is not pretty packaged. You’d have to know how to fix your own JAVA paths and get it to work.


#19

Good catch. Just an erroneous copy/paste of the find min solution on my part. Sorry about that. The answer key has been updated.

Thanks!

Baker
CSP Team


#20

Yeah…making a widget for this is one of my pet projects. I’ve made some prototypes in App Lab but nothing terribly robust. I’m glad you did this. If you want to send it to me baker[at]code.org I’d be happy to look.

If you wanted to distribute it for other teachers that would be great help. Is it command line only right now?