Name: Anonymous 2007-09-24 4:44 ID:qljv4pIe
I have a fun little programming contest for y'all! You are writing a function named foo() that takes in five arguments and outputs a 32-bit integer. The user who writes the most efficient solution meeting all of the specifications outlined below will receive a $10 cash prize. (We have thousands of test cases to spread out the results.)
function foo(a, b, c, d, e) {
// your code goes here
return out;
}
Inputs:
u8 a; // range: 0-24
bool b;
u8 c; // range: 0-255
bool d;
u32 e; // range 0-2^32-1
Output:
u32 out; // range 0-2^32-1
Here are the four restrictions for the output:
1. (out mod 25) must be equal to a
2. if b = FALSE, then out mod 255 must be between 0 and c-1, inclusive
3. if b = TRUE, then out mod 255 must be between c and 255, inclusive
4. if d = TRUE, then ((out XOR e) / 65536) XOR (out XOR e) % 65536)) must be < 8
Example:
foo(1, 0, 31, 1, 0) returns 1, which satisfies all of the conditions above.
foo(3, 1, 31, 1, 3162282670) returns 4063024378
There may be several possible values for out, but a value that satisfies all four conditions above must be returned.
You may use Java, C, or C++.
All solutions should be sent to markus.yeh (at) gmail.com . Only your most recent submission will be entered into the contest. The entry deadline is Wednesday, September 26 at 12:00 a.m. Pacific Time, and winners will be announced before Saturday, September 29 at 12:00 a.m. Pacific Time.
Good luck!
function foo(a, b, c, d, e) {
// your code goes here
return out;
}
Inputs:
u8 a; // range: 0-24
bool b;
u8 c; // range: 0-255
bool d;
u32 e; // range 0-2^32-1
Output:
u32 out; // range 0-2^32-1
Here are the four restrictions for the output:
1. (out mod 25) must be equal to a
2. if b = FALSE, then out mod 255 must be between 0 and c-1, inclusive
3. if b = TRUE, then out mod 255 must be between c and 255, inclusive
4. if d = TRUE, then ((out XOR e) / 65536) XOR (out XOR e) % 65536)) must be < 8
Example:
foo(1, 0, 31, 1, 0) returns 1, which satisfies all of the conditions above.
foo(3, 1, 31, 1, 3162282670) returns 4063024378
There may be several possible values for out, but a value that satisfies all four conditions above must be returned.
You may use Java, C, or C++.
All solutions should be sent to markus.yeh (at) gmail.com . Only your most recent submission will be entered into the contest. The entry deadline is Wednesday, September 26 at 12:00 a.m. Pacific Time, and winners will be announced before Saturday, September 29 at 12:00 a.m. Pacific Time.
Good luck!