Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume two boxes (box \"A\" and box \"B\"). Each contains zero or more pennies.

ID: 3837145 • Letter: A

Question

Assume two boxes (box "A" and box "B"). Each contains zero or more pennies. What will be left in the boxes after the instructions below are executed if i) "A" contains 11 pennies, "B" contains 2 pennies ii) "A" contains 5 pennies, "B" contains 7 pennies if box "A" contains more than 6 pennies then while box "A" contains more pennies than box "B" do if box "A" contains more than 4 pennies then move 4 pennies from box "A" to box "B" else move 1 penny from box "A" to box "B" endif endwhile else move everything in box "B" to box "A" endif

Explanation / Answer

[1] A-11 B-2
IF -True
While 11>2 True
     IF True A = 7 B = 6
While 7 > 6 True
     If True A = 3 B = 10
While 3 > 10 False
End While

After instruction :

Box A : 3
Box B : 10


-------------------------------------------------

[2] A-5 B-7
IF - False
Else -
   A = 12 B = 0

After instruction :

Box A : 12
Box B : 0