JavaScript - 41 (up to 46) 37 35 34 30
Updated:
Managed to get it down to 30 chars by modifying it, inspired by stevevarrill's answer in C.
C=A-B?6-A-B:1+(A+new Date%2)%3
Thank you nyuszika7h for getting me down to 34~:
C=A;while(C==A|C==B)C=1+new Date%3
Borrowing from xem's answer to at least fall on par with him:
C=A;while(C==A||C==B)C=1+new Date%3
Thanks for reminding me that 1+new Date%3 === (new Date%3)+1
!
Previous Solution:
C=A;while(C==A||C==B)C=(new Date%3)+1
Ensure conditions of while()
are satisfied, and loop through until they're not.
Other solution:
C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1;
This assumes that C
has already been declared OR that the JavaScript interpreter can handle undeclared variables.
However, if the JS interpreter can handle EOL without a semicolon, it could be bumped down to 41.
C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1
If C
hasn't been declared, and there is no error correction for it, that will bring the tally up to 46 characters.
var C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1;
Test Program:
var iterations = 100;
for(var i = 0;i<iterations;i++) {
var A = Math.floor(Math.random() * 3) + 1;
var B = Math.floor(Math.random() * 3) + 1;
C=A!=B?6-A-B:A%2!=0?4-B:new Date%2!=1?3:1
if (C === A || C === B || C > 3 || C < 1) {
console.log('FAILURE!');
console.log(A + ',' + B + ',' + C)
return;
}
console.log(A+','+B+','+C);
}