Memory registers puzzle

51 Views Asked by At

There are 3 memory registers: A, B and C. Following are the 3 valid commands:

1) copy from A to C

2) copy from B to C

3) Replace A by A - C

How can these commands be used to copy from B to A?

1

There are 1 best solutions below

6
On

Copy $A$ to $C$

Replace $A$ by $A-C$ # A is now initialized to $0$

Copy $B$ to $C$

Replace $A$ by $A-C$ # $A$ now contains $-B$

Copy $A$ to $C$ # $C$ now contains $-B$

Replace $A$ by $A-C$ # A is now reinitialized to $0$

Replace $A$ by $A-C$ # $A$ now contains $B$