Alien Intercourse
New member
Hi this is a test i sat yesterday for a job interview, I have a question from that...
Suppose there is a virtual computer that uses Registers A, B and C only.
You can use 4 instructions: ADD Subtract, multiply and divide.
Each instruction takes 2 operands and one result. e.g. A+A -> A ; adds A to itself stores/overwrites it in A or A + B -> C; adds A and B and overwrites the result in C
Note:
* Division by 0 is not allowed.
* Use or literals are not allowed e.g. invalid statement: A + 2 -> B
* Move is not allowed e.g. A -> B
* virtual computer throws away the Remainder from the Division.
* Only 2 operands and a result instruction is allowed.
Sample question:
Given that A = 5 , B = 3 and C = 4
write Steps to put 17 in C
Answer:
A * C -> A A - B -> C
Sample question 2
A and B contain integers, C contains either 0 or 1, write steps to move A to C if C == 1 or B to C if C == 0. So write steps to move A or B depending on the value of C
Answer:
Start with
A <- A - B
C <- A * C
C <- B + C
And there you have it. Mathematically, it's boils down to:
C <- B + C(A - B)
When C is 0, C(A - B) is also 0, so you end up with B.
When C is 1, C(A - B) is A - B, so you end up with B + A - B or A.
"NEW" Question ::::
Now there are 4 Registers available to use - A , B , C and D. Contents of A and B are integers, while C and D are unknown.
Write steps to move the greater of A or B to C.
Please help me out thank you.
dont say its impossible, because its not there is an answer. or else it wont be in the test.
Suppose there is a virtual computer that uses Registers A, B and C only.
You can use 4 instructions: ADD Subtract, multiply and divide.
Each instruction takes 2 operands and one result. e.g. A+A -> A ; adds A to itself stores/overwrites it in A or A + B -> C; adds A and B and overwrites the result in C
Note:
* Division by 0 is not allowed.
* Use or literals are not allowed e.g. invalid statement: A + 2 -> B
* Move is not allowed e.g. A -> B
* virtual computer throws away the Remainder from the Division.
* Only 2 operands and a result instruction is allowed.
Sample question:
Given that A = 5 , B = 3 and C = 4
write Steps to put 17 in C
Answer:
A * C -> A A - B -> C
Sample question 2
A and B contain integers, C contains either 0 or 1, write steps to move A to C if C == 1 or B to C if C == 0. So write steps to move A or B depending on the value of C
Answer:
Start with
A <- A - B
C <- A * C
C <- B + C
And there you have it. Mathematically, it's boils down to:
C <- B + C(A - B)
When C is 0, C(A - B) is also 0, so you end up with B.
When C is 1, C(A - B) is A - B, so you end up with B + A - B or A.
"NEW" Question ::::
Now there are 4 Registers available to use - A , B , C and D. Contents of A and B are integers, while C and D are unknown.
Write steps to move the greater of A or B to C.
Please help me out thank you.
dont say its impossible, because its not there is an answer. or else it wont be in the test.