|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On September 11 2015 11:50 Housemd wrote: Hey guys, another stupid simple question that I can't seem to figure out.
int a = 10; int b = 5; int c = a+b: if (a+b) = 189 { cout << "I'm the best"<<end1; } else { cout << "I suck at programming"<<end1; }
so basically, i don't get one thing. obviously a+b doesn't equal 189 but i keep getting only the former boolean condition. Meaning it keeps printing "I'm the best." Can someone guide me through this issue?
EDIT: This is c++. Just using an online compiler.
EDIT: NVM I'm stupid. supposed to be if (a+b) == 189.
Your compiler must be pretty nice to compile this code for you.
|
Does anyone know of some fun number logic questions, ideally the kind that get asked in interviews?
|
You should not be getting asked number logic questions in interviews. Or at least, what sort of position are you talking about?
|
On September 14 2015 15:21 phar wrote: You should not be getting asked number logic questions in interviews. Or at least, what sort of position are you talking about? A friend of mine had an interview for a firmware programming position (graduate position) and had a series of number logic questions. For example, in 3 steps take boxes X Y and Z with any numbers in X and Y and 0 in Z and only using + and - operators (and one operation per step) to swap X and Y.
EDIT perhaps that's not a "good interview" but if it does happen then I want to prepare for it, optimal interview style or not. And the puzzles are quite fun to work out anyway.
|
On September 14 2015 16:18 Birdie wrote:Show nested quote +On September 14 2015 15:21 phar wrote: You should not be getting asked number logic questions in interviews. Or at least, what sort of position are you talking about? A friend of mine had an interview for a firmware programming position (graduate position) and had a series of number logic questions. For example, in 3 steps take boxes X Y and Z with any numbers in X and Y and 0 in Z and only using + and - operators (and one operation per step) to swap X and Y. EDIT perhaps that's not a "good interview" but if it does happen then I want to prepare for it, optimal interview style or not. And the puzzles are quite fun to work out anyway.
That's actually fun. Do you mean something like that?
+ Show Spoiler + X = 10; Y = 5; Z = 0;
Z = X + Y; Y = Z - Y; X = Z - X;
|
On September 14 2015 17:45 Manit0u wrote:Show nested quote +On September 14 2015 16:18 Birdie wrote:On September 14 2015 15:21 phar wrote: You should not be getting asked number logic questions in interviews. Or at least, what sort of position are you talking about? A friend of mine had an interview for a firmware programming position (graduate position) and had a series of number logic questions. For example, in 3 steps take boxes X Y and Z with any numbers in X and Y and 0 in Z and only using + and - operators (and one operation per step) to swap X and Y. EDIT perhaps that's not a "good interview" but if it does happen then I want to prepare for it, optimal interview style or not. And the puzzles are quite fun to work out anyway. That's actually fun. Do you mean something like that? X = 10; Y = 5; Z = 0;
Z = X + Y; Y = Z - Y; X = Z - X;
Yes, but there were some additional rules which I didn't bother mentioning. Here's what I can recall of the problem:
Here are the additional problems that I can recall. I suggest you spoiler your answers so other people can try, if there is any interest in this thread 
Note: You can add boxes to themselves (X = X + X), and for + and * place the result in any box (X = Y + Z).
+ Show Spoiler [Problem 0] + Rule 1: Only + and - operators may be used. Rule 2: Only one operation per step. Rule 3: The - operator must return the result into the operand to the left of the operator (e.g. Z - X must be put into Z, not into X) Rule 4: All operations are integer operations (5 / 3 = 1, not rounded but truncated to 1).
X and Y can be any integer number (and must work for any number) at step 0. Z = 0 at step 0.
In four (I think it was four now, originally said three) steps, swap the values in X and Y.
+ Show Spoiler [Problem 1] + Rule 1: Only the + operator may be used. Rule 2: Only one operation per step.
Initial values: X = 10, Y = 15, Z = 20. After 3 steps, make Y = 55 and Z = 60 (X can be anything).
+ Show Spoiler [Problem 2] + Rule 1: Only + - / and * operators may be used. Rule 2: Only one operation per step. Rule 3: All operations are integer operations (5 / 3 = 1, not rounded but truncated to 1). Rule 4: The / and - operators must return the result into the operand to the left of the operator (e.g. Z - X must be put into Z, not into X).
X at step 0 is 8 when Y at step 0 is 9, and vice versa. The algorithm must work for both (X=8, Y= 9) and (X=9, Y=8). Z is empty. After two steps, Z must equal 9 (for both initial sets of values).
+ Show Spoiler [Problem 3] + Rule 1: Only + and - operators may be used. Rule 2: Only one operation per step. Rule 3: All operations are integer operations (5 / 3 = 1, not rounded but truncated to 1). Rule 4: The - operator must return the result into the operand to the left of the operator (e.g. Z - X must be put into Z, not into X).
For any initial values of X, Y, and Z, after four steps Z must equal X + 2Y - 3Z (the final value of Z must equal the initial value of X + 2x the initial value of Y - 3x the initial value of Z).
Example inputs and output: X=1, Y=2, Z=3. Output: Z=-4 (1 + 2(2) - 3(3))
|
On September 14 2015 18:05 Birdie wrote: Rule 3: The - operator must return the result into the operand to the left of the operator (e.g. Z - X must be put into Z, not into X)
Note: You can add boxes to themselves (X = X + X), and for + and - place the result in any box (X = Y + Z).
Aren't you contradicting yourself here?
In any case there seems to be an awful lot of rules which won't really help show whether you're intelligent/quick-witted or whatever they wanted to see from your solutions. Unless they wanted to test your perseverance.
|
On September 14 2015 18:11 spinesheath wrote:Show nested quote +On September 14 2015 18:05 Birdie wrote: Rule 3: The - operator must return the result into the operand to the left of the operator (e.g. Z - X must be put into Z, not into X)
Note: You can add boxes to themselves (X = X + X), and for + and - place the result in any box (X = Y + Z).
Aren't you contradicting yourself here? Sorry, meant for + and * place the result in any box. Fixing now!
|
|
On September 14 2015 18:18 Manit0u wrote: Can you do X = -X - -Z? No. I think that would count as more than one operation in a step more or less.
|
|
On September 14 2015 21:35 Nesserev wrote:I don't know if I completely understood the questions, might have missed something. + Show Spoiler [question 1] + X = 10, Y = 15, Z = 20
X = Z + Z // X = 20 + 20 = 40 Y = Y + X // Y = 15 + 40 = 55 Z = Z + X // Z = 20 + 40 = 60
X = 40, Y = 55, Z = 60
+ Show Spoiler [question 2] + X = 8, Y = 9, Z = (/) or X = 9, Y = 8, Z = (/)
X = X / Y // X = 0 or X = 1 Z = Y + X // Z = 9 + 0 = 9 or Z = 8 + 1 = 9 (finished now) Z = Z + X Z = Z - X
Z = 9
Haven't started the third one yet. Correct so far. I think I mis-remembered the number of steps problem 2 required but your technique is correct. I will edit my post.
|
Bisutopia19152 Posts
|
Bisutopia19152 Posts
On September 14 2015 21:35 Nesserev wrote:I don't know if I completely understood the questions, might have missed something. + Show Spoiler [question 1] + X = 10, Y = 15, Z = 20
X = Z + Z // X = 20 + 20 = 40 Y = Y + X // Y = 15 + 40 = 55 Z = Z + X // Z = 20 + 40 = 60
X = 40, Y = 55, Z = 60
+ Show Spoiler [question 2] + X = 8, Y = 9, Z = (/) or X = 9, Y = 8, Z = (/)
X = X / Y // X = 0 or X = 1 Z = Y + X // Z = 9 + 0 = 9 or Z = 8 + 1 = 9 (finished now) Z = Z + X Z = Z - X
Z = 9
Haven't started the third one yet. High five bro! We got the solutions the same way. Although I feel like question #2 has more then one correct answer.
|
On September 14 2015 07:00 darkness wrote:Show nested quote +On September 11 2015 11:50 Housemd wrote: Hey guys, another stupid simple question that I can't seem to figure out.
int a = 10; int b = 5; int c = a+b: if (a+b) = 189 { cout << "I'm the best"<<end1; } else { cout << "I suck at programming"<<end1; }
so basically, i don't get one thing. obviously a+b doesn't equal 189 but i keep getting only the former boolean condition. Meaning it keeps printing "I'm the best." Can someone guide me through this issue?
EDIT: This is c++. Just using an online compiler.
EDIT: NVM I'm stupid. supposed to be if (a+b) == 189. Your compiler must be pretty nice to compile this code for you. 
You mean the compiler is naughty for not throwing an error.
|
Bisutopia19152 Posts
On September 15 2015 00:43 Sufficiency wrote:Show nested quote +On September 14 2015 07:00 darkness wrote:On September 11 2015 11:50 Housemd wrote: Hey guys, another stupid simple question that I can't seem to figure out.
int a = 10; int b = 5; int c = a+b: if (a+b) = 189 { cout << "I'm the best"<} else { cout << "I suck at programming"<}
so basically, i don't get one thing. obviously a+b doesn't equal 189 but i keep getting only the former boolean condition. Meaning it keeps printing "I'm the best." Can someone guide me through this issue?
EDIT: This is c++. Just using an online compiler.
EDIT: NVM I'm stupid. supposed to be if (a+b) == 189. Your compiler must be pretty nice to compile this code for you.  You mean the compiler is naughty for not throwing an error. My brain had to throw a few exceptions to process that code.
|
On September 14 2015 22:15 BisuDagger wrote:+ Show Spoiler [Problem 1 solution] + x = 10 y = 15 z = 20
x = z + z; // x = 40 y += x; // y = 55 z += x; // x = 60
+ Show Spoiler [Problem 2 solution] + (X=8, Y= 9) and (X=9, Y=8) x = 8 y = 9 z = null
x /= y z = x + y z *= z z /= z
Problem 3 is not written clearly. If they gave me the question that way, I'd hand it back to them and move on. I hope you just didn't write it clearly. What is unclear about it?
EDIT I've added example inputs and outputs to problem 3, and put up problem 0 into a spoiler as no one was answering that one.
|
+ Show Spoiler [Problem 0] + X = X Y = Y Z = 0
X = X - Y Y = Y + X //Y = Y + (X - Y) = X Z = Z - X //Z = 0 - (X - Y) = -X + Y X = Z + Y //X = (-X + Y) + X = Y
(fixed)
+ Show Spoiler [Problem 3] + X = X - Z //X = X - Z Y = Y - Z //Y = Y - Z Y = Y + Y //Y = (Y - Z) + (Y - Z) = 2Y - 2Z Z = X + Y //Z = (X - Z) + (2Y - 2Z) = X + 2Y - 3Z
|
Y = Z is invalid as you didn't use an operation (other than assignment). Solution to 3 looks correct, although there's another way to do it which is slightly different (but same thought process).
|
On September 15 2015 00:43 Sufficiency wrote:Show nested quote +On September 14 2015 07:00 darkness wrote:On September 11 2015 11:50 Housemd wrote: Hey guys, another stupid simple question that I can't seem to figure out.
int a = 10; int b = 5; int c = a+b: if (a+b) = 189 { cout << "I'm the best"<<end1; } else { cout << "I suck at programming"<<end1; }
so basically, i don't get one thing. obviously a+b doesn't equal 189 but i keep getting only the former boolean condition. Meaning it keeps printing "I'm the best." Can someone guide me through this issue?
EDIT: This is c++. Just using an online compiler.
EDIT: NVM I'm stupid. supposed to be if (a+b) == 189. Your compiler must be pretty nice to compile this code for you.  You mean the compiler is naughty for not throwing an error.
It was irony. Of course, compiler should display an error.
|
|
|
|