# '16-'17 General Discussion for Lesson 3.3

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

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:

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.

Yikes. Good catch.

Baker
CSP Team.

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

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

@trae.cooper

I think you might be rightâ€¦ Perhaps Line 7 should check if RHPos gt 0â€¦

Andrea

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]

1 Like

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

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

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â€¦

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

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)

2 SWAP
4 SHIFT RH to the R
6 END

Bubble sort technique to come.

It is fun to mess around
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

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

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
3 SWAP
5 SHIFT LH to the L
6 SHIFT RH to the L
8 END

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.

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.

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.

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

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?

1 Like