Ok, this is my solution to the TISC question:
STO A,1 -- Write register a to mem 1
SUB A,0 -- Set register a to ('a-$0)
SUB A,1 -- Set register a to ('a-$0)-$1=='a-$0-'a==$0
STO A,1 -- Write register a (which is now $0) to mem 1
Note that 'a in the comments is the inital value of register a, it's not the updated value. So this should work as expected, with only one register and 4 instructions.
Game programming test(Interview test)
Well, my roommate solution was only one register too, but I don,t see a case where yours doesn't work. Nice. I didn't touch the problem at all for that matter, just sent my roommate answer to Halifax for confirmation, that's all.
I can see something like that in a test. And while that solution, if no problem arise IS better, if the question asked for the solution in 7 steps (which is unclear in Halifax post), I know some places that would actually see it as only a partial answer because it does not meet the criteria. Giving both answer might give bonus points on the other hand. No matter, I'm interested to know if Hybrid's answer can be wrong in some context. I don't think so, but I'd like to know
I can see something like that in a test. And while that solution, if no problem arise IS better, if the question asked for the solution in 7 steps (which is unclear in Halifax post), I know some places that would actually see it as only a partial answer because it does not meet the criteria. Giving both answer might give bonus points on the other hand. No matter, I'm interested to know if Hybrid's answer can be wrong in some context. I don't think so, but I'd like to know
If my test case serves me correct, that doesn't work. The value swapped to $1 is negative $0:hybrid wrote:Ok, this is my solution to the TISC question:
STO A,1 -- Write register a to mem 1
SUB A,0 -- Set register a to ('a-$0)
SUB A,1 -- Set register a to ('a-$0)-$1=='a-$0-'a==$0
STO A,1 -- Write register a (which is now $0) to mem 1
Note that 'a in the comments is the inital value of register a, it's not the updated value. So this should work as expected, with only one register and 4 instructions.
Code: Select all
$0 - 24
$1 - 31
A - 12
B - 15
STO A,1 ($1 = 12)
SUB A,0 (A - $0 = 12 - 24 = -12)
SUB A,1 (A - $1 = -12 - 12 = -24)
STO A,1 ($1 = -24)
$1 = -24
TheQuestion = 2B || !2B