# KEYS AND BOXES SOLUTION

Assume, without loss of generality, that the robot's initially-held object is ?, where ? is one of the unknown items at the non-keys box.

1. goto box1
2. put down
; if box1 had only keys, then it now has keys + ? (Case A)
; if box1 had only ?, then it now has only ? (Case B)
3. goto door
4. pick up
; robot picks up red item
5. goto table
6. put down
; table only has one red item
7. goto box1
8. pick up
; Case A: if robot has picked ?, then box1 only has keys (Case A1)
;              if robot has picked key, then box1 has keys + ? (Case A2)
; Case B: robot has ?
9. goto door
10. put down
; Case A1: box1 has only keys, box2 has only ?, door has ?
; Case A2: box1 has keys + ?, box2 has only ?, door has key
; Case B: box1 has only ?, box 2 has only keys, door has ?
11. goto box1
12. pick up
; Case A1: robot has key
; Case A2: if robot picked ?, then box1 has only keys (Case A2.1)
;                if robot picked key, then box1 has keys + ? (Case A2.2)
; Case B: robot has ?
13. goto door
14. put down
; Case A1: door has key + ?
; Case A2.1: door has key + ?
; Case A2.2: door has 2 keys
; Case B: door has 2 ?
15. goto box2
16. pick up
; Case A1: robot has ?
; Case A2.1: robot has ?
; Case A2.2: robot has ?
; Case B: robot has key
17. goto door
18. put down
; Case A1: door has key + 2 ?
; Case A2.1: door has key + 2 ?
; Case A2.2: door has 2 keys + ?
; Case B: door has key + 2 ?
19. goto table
20. pick up
; robot has red item
21. goto outside
; since door has key in all 4 cases, robot can go outside with red object