- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Try this one for size (can't take credit for it... search for HACKMEM 169)
int num_bits_set(uint32_t n) { uint32_t tmp = n - ((n >> 1) & 0xDB6DB6DB) - ((n >> 2) & 0x49249249); return ((tmp + (tmp >> 3)) & 0xC71C71C7) % 63; }
Fair play if you can remember it in order to throw it out at an interview though.
Admin
Manhole covers are round because manholes are round.
captcha: ewww
Admin
Not true.
<lament>Why did they ever lower the mathematics standards for computer science?</lament>
Try this.
What is 1/11? (answer: 0.0909, repeating) What is 10/11? (answer: 0.9090, repeating)
What is 1/11 + 10/11? (answer: 0.9999, repeating)
As a fraction, what is 1/11 + 10/11? (answer, 11/11, or in simplest form, 1)
Captcha: dubya (how appropriate)
Admin
I'd like to point out that you would have failed by not being able to fully understand the problem given.
Admin
Microsoft innovated this, proving it was a dumb idea; but it had good intentions... ;)
Seriously though, they gave these to engineering students like myself. Out of ten occasions (yes! ten over my college "career"!) I solved it once or twice. By the last occasion I realized I had no interest in working for a company who put so much importance on these teasers, no matter how good their benefits may be.
Not long after I received an interview at silicon valley firm. I had only programmed on their platform on a couple of occasions, and I never used the progamming language they enourage. Despite this, they sent me an offer based ony my C++ skills and my interest in the area they were looking for.
No brainteaser bullshit. They hired me based ony what I could offer them and how well they felt I could work with the other members of the project team.
Now if only more companies did that... ;)
Admin
And another one in Java
Results:
Admin
Let's try this instead. 1/3 = 0.333... Yes? If you do the division, you see that it does. I hope we can agree on this.
1/3 + 1/3 + 1/3 = 0.333... + 0.333... + 0.333... 3/3 = 0.999... 1 = 0.999...
This is not trick mathematics, this is a fact.
Admin
Admin
Anyone not willing to wait a day for the interview process for all candidates to complete is not worth hiring. I'd tell the candidate as much and ask if they are withdrawing or not. If they say yes I'd show 'em the door. Making unreasonable demands before you've even got an offer is completely unacceptable.
Of course the same goes the other way round. Any company not willing to let you think over an offer over night isn't worth working for.
Admin
As far as I can see, brainteasers are a corruption of a reasonably sound idea. I originally heard the brainteasers as things more like 'how many gas stations are there in Los Angeles?' - they have no 'right' answer, so it's clear that no-one cares if you're off by a factor of ten. What they want to see is how you'd tackle an unknown problem, whether you'd dive right in and come up with a reasonable thought process or whether you'd just sit there and stammer.
The one I got in my interview had to do with compression schemes. The interviewer knew in advance that it was irrelevant and I didn't know much about it, which is the point - how do you respond to a question you don't know the answer to?
Admin
The problems with this one come about because of an (admittedly counter-intuitive) fallacy about repeating numbers.
Perhaps a good way to illustrate it is to find the result of 1 - 0.999... It seems to come out, intuitively, as 0.000...0001, but this result implies that repeating numbers have an end, and we just don't bother writing it - which is false.
It's perhaps easier to subtract 1.000... and 0.999... which works out to 0.000..., which is 0.
Admin
Half right. There are two shapes that won't fall in. Round covers won't fall in, and triangular covers won't fall in.
So the correct answer is: "The covers are round because they're easier to manufacture than triangular ones. (And easier to use, too.)"
Admin
Admin
Hmm, I have no idea what the 'correct' answer is, but this is how I'd do it with branching:
Where eax holds the random 32 bit number on entry, and eax stores the result at the end.
@Ret: ret
Takes linear time + constant based on the number of set bits, as required. Here's how you'd do it without branching, and in constant time:
X := X - (X shr 1) and ($55555555); X := (X shr 2) and ($33333333) + X and ($33333333); X := ((X shr 4) + X) and ($0F0F0F0F); X := (X * $01010101) shr 24;
Well, in pascal at least. I wrote the first function, the second one is from bit twiddling hacks.
Admin
Yes, but no one can be wrong, and you all have to either guess or pass simultaneously, so you can't use the information from the other two's answer.
If you can take off the hat and look at it, then the problem is trivial.
If you can communicate a binary signal through non-verbal means, then you can let the other two know whether their hats match, and they can both answer correctly. For example, agree to sit down if the hats match.
If no communication whatsoever is allowed, then you might as well be in separate rooms, so use the strategy session to pick someone to guess, and have the other two pass. That gives you a 50% chance of success.
Admin
The seeing-eye dog sits in the sidecar.
Admin
The bad news is, you need to put on the dunce cap.
The good news is someone should be along shortly to wear it in your place.
Read the thread, nearly half the posts explain why the intuitive answer is wrong.
Admin
How about this? public static int BitCount(int x) { return ((x == 0) ? 0 : ((x < 0) ? 1 : 0) + BitCount(x <<= 1)); }
Admin
Here's another... I don't remember where I heard it:
Given a random 32-bit integer, write some code that will count the number of set bits (i.e., 1's) in O(n) time, where n is the number of set bits. Use your favorite language that has bit-wise operators.
How about this? public static int BitCount(int x) { return ((x == 0) ? 0 : ((x < 0) ? 1 : 0) + BitCount(x <<= 1)); }
Admin
How about this?
public static int BitCount(int x) { return ((x == 0) ? 0 : ((x < 0) ? 1 : 0) + BitCount(x <<= 1)); }
Admin
Well, manhole covers used to be square, but here in the U.S. we cut corners so often that they are just round now!
...a nice isosceles triangular 'cover'... whoops.. lost it!
Admin
If anyone still cares, here goes: 0.999...
Admin
Well, it has to be a specific type of 'triangle', where the diameter is constant. (under those conditions, any odd-sided polygon would work just as well.)
cite: http://www.straightdope.com/classics/a1_247a.html
captcha: alarm
Admin
I knew the answer to one of the three brainteasers in the original article right away, because I had heard and solved it before, many years ago. My first thought of what I'd do if this had happened to me in a job interview was to tell the answer straight away ("turn on one of the switches, wait a while, turn it off, turn a second one on, leave it on, leave the third one off; open the box: the light that is off but warm belongs to the first switch, the light that is on to the second, and the light that is off and cold to the third") and then say I knew the answer and ask for another brainteaser.
I don't really like brainteasers, but that felt like the right thing to do. I could, of course, explain the background idea ("need to use more information than just light on/off, bla bla"), but this still would not really show the process of discovering the answer, and I agree with you that this process is really what the interviewer is looking for.
So, had I recited the answer from memory and then asked for another one, would I still have received an immediate "no" from you? ;)
Admin
You can't prove by example. What you did is disprove by counterexample ;)
Admin
The above table models the statement: "3 people can have one of two hats (R0 or B1)"
But not the statement: "3 people can have one of six hats (R1,R2,R3,B1,B2,B3), three of which are red, and the remainder are blue"
Writing a table for this statement is a lot bigger though, and I'm not good at stats. But from this snippet, you can see that 3 red hats is 3 times less likely to occur than 2 red and 1 blue (even though all hats are 50/50)... Hence in the above table, the event "000" has a lower probability than the event "001" (which, if anything, cements the existing strategy).
000 = 6/total outcomes R1 R2 R3 R1 R3 R2 R2 R3 R1 R2 R1 R3 R3 R1 R2 R3 R2 R1
001= 18/total outcomes R1 R2 B1 R1 R2 B2 R1 R2 B3 R1 R3 B1 R1 R3 B2 R1 R3 B3 R2 R1 B1 R2 R1 B2 R2 R1 B3 R2 R3 B1 R2 R3 B2 R2 R3 B3 R3 R1 B1 R3 R1 B2 R3 R1 B3 R3 R2 B1 R3 R2 B2 R3 R2 B3
Admin
Please read the riddle again. Specs, sweetheart, specs. And the importance of reading them carefully and thoroughly.
Admin
I felt it irrelevant to consider payload since it was not mentioned.
Admin
3 men and hats ... at the initial strategy session you tell everyone that if they see two hats of different colours , they are to say "PASS" within 30 seconds of entering the room.
If you hear 1 pass , then your hat is the same colour as the person who said pass , If you hear two passes , then your hat is the opposite colour of the other two who have the same ...
If you hear no "passes" then you all have the same colour .
Easy . and 100% correct ..
Admin
My bad, meant to quote someone replying to my comments on the weight of an empty boeing 747
Admin
I think this is what I was trying to remember: let x = 0.99º 10x = 9.99º 10x - x = 9 9x/9 = 1 0.99º = 1
Admin
Won't work - you have to give your answer simultaneously. This is easily enforced by forcing the participants to secretly write down their answer or forfeit their prize. Again specs. People seem to think a loophole is located here: "Each person can see the other players' hats but not his own." (to be rephrased like "Each person is allowed to see the other players' hats but not his own.") Not true. A) It may be possible that the players are physically restricted so that they really can't see their hats. B) "Can" also means "to be allowed to" as in "Can I ... ?" If you take your hat of, look in the mirror, etc., you're screwed. You could try to surrepticiously communicate, but you're screwed if caught. Also you may find communication to have been sufficiently resistricted by the quizmaster upon entry, in which case you need a backup plan.
Admin
you fail... the prize is only won if at least one player is right and none are wrong, using your strategy you will fail more than 85% of the time. Best solution strategy, if the other players hats are different colors pass, if the other two players hats are the same color, guess eh opposite color.
Admin
2 guys/2 girls/2 condoms - simple....send guy 2 out to get several more boxes of condoms, you have both girls with one condom each, when guy 2 gets back you both have them both as many times as you like! Hey, it didn't say ONLY 2 condoms :-D
How to move the mountain to the other side of the town - rotate the map 180 degrees! (much easier than relocating an entire town)
Admin
I had a job interview recently and in it I was given one of these riddles. How high will the oceans rise if Antarctica melted?
I knew the answer off the top of my head (apprx. 190 ft) but my interviewer wouldn't let me off with just giving him the right answer, he wanted to know how I got it; sadly, "I just know" isn't a good answer. I tried to figure it out for him, but just the way he looked at me while I was talking about it made me irritated and I got frustrated. I thought for sure I botched the interview because of that.
Admin
Grandpa you better shove that code to yourself....and fuck off okie....shove it deep into your stinking asshole....I'm a real good programmer who was screwd by sonsofbitches like you.
Admin
You guys are like rabid rabbits on that hat problem. I am not touching that.
But the coin thing should be 2 or 3 measures. Since there are 8 coins with 2 possible values, eg: 0 or 1 that means 16 possible values.
2 or 3 guesses is all you need. This reminded me of matrix multiplication for some reason.
Assuming: We don't know if the coin is heavier or lighter than the others, just not the same weight as the other 7. Eg: we cannot asume that it will cause a result of higher or lower no matter what combination of coins we use. (50/50 rule is straight out) Why throw away the coins/data when you can use them/it to help prove the problem? :)
7 heavier 123 456 78 -> 123 456 equal 78 suspect 1 234 567 8 -> 234 higher 1 and 8 equal by being outside testing bounds. 7 is the only possible odd.
1 heavier 123 456 78 -> 123 low 456 high, 78 equal outside of bounds 1 234 567 8 -> 234 5678 equal, 1 is only one left.
3 lighter (worst case, just like if 2 or 5 was the odd coin) 123 456 78 -> 123 high 456 low, 78 equal 1 234 567 8 -> 234 high 567 low, same result, 145678 equal, 23 suspect 12 345 678 -> 345 high 678 low, 2 is now equal to the rest, 3 odd.
And the sex questions, eww eww eww, at least they could have rephrased the questions.
On a side note, wouldn't a manhole cover be fine if the rim of the hole was half or more of the distance than the object to be placed upon it?
What I mean is if we have a square manhole cover, say 2 feet x 2 feet, if the rim that holds it in place is .5 feet on each side, it works just as well as a circular cover.
A circle just makes this a bit less wasteful I would think.
Admin
I find it extremely ironic that a site which's purpose is to ridicule at other people's stupidity and incompetence is filled with this many idiots who can't read and understand simple instructions to a simple puzzle. This time the WTF is the comments not the post itself.
Admin
Correct, but the strategy for 3 hats doesn't generalize naively to the case with more than 3 hats. You can do a lot better.
What you want for n hats is essentially a single error correcting code with codewords of length n with as many codewords as possible (i.e. 2^n/(n+1)). If you can do this perfectly (and you can if n is of the form 2^k-1, with a Hamming code) you succeed with probability n/(n+1).
The strategy is as follows: for each player, if the hats might form a codeword based on what they can see the other people wearing, they should guess the hat color opposite to the one that completes the codeword, otherwise they should stay silent. This has the desired effect of concentrating all the wrong guesses together (on the codewords) and spreading out the correct guesses (everywhere else).
For a concrete example, suppose 7 hats. Take the 16 hat distributions 0000000, 0000111, 0011001, 0011110, 0101010, 0101101, 0110011, 0110100, 1001011, 1001100, 1010010, 1010101, 1100001, 1100110, 1111000, 1111111. The assiduous reader can check that the other 112 hat distributions each differ in just one place from one of these 16. So this gives you a strategy that succeds with probability 7/8.
example, since my explanation's probably unclear: if the distribution is 0010001, then the middle guy sees 001?001 and so says 0, since 0011001 is in the list above. No-one else sees something which could be in the list, and so no-one else speaks, and the game is won.
Admin
Admin
Admin
Admin
Multiple solutions are possible. Fill the 5 litre jar with water. Fill the 3 litre jug with the 5 litre jug. Now the 5 litre jug will have exactly 2 litres. Empty the 3 litre jug and pour the 2 litres from the 5 litre jug to the 3 litre jug. Fill the 5 litre jug and try to fill the 3 litre jug, since the 3 litre jug has already 2 litres, it will hold only a additional litre. Now the 5 litre jug will exactly have 4 litres
Simple, a) They are usually very heavy (so that no one can easily steal them). Round shaped ones can be easily rolled on the ground for moving. b) A round shaped one will not fall inside the manhole at any angle. A square or a rectangular shaped one can. Step1: Man takes chiken to the other side and comes back alone Step2: Man takes grain to the other side and comes back with the chicken Step3: Man takes fox to the other side and comes alone Step4: Man takes chicken to the other side.I am a good programmer too:)
Admin
(possibly someone already solved but I didn't have the time to browse 6 pages of comments :P)
Stand in a triangle, facing eachother. If you see a red hat to the left of you, be silent at first. If you see a blue hat to the left of you, say you pass. If the person to the right of you passes you have a blue hat so you say "blue", if the person to the right of you says nothing, say "pass"...
It's not 100% simultaneous, and it's not without communication per sé since being silent or saying you pass is a form of communication, but they observer might not notice and you'd walk away with $3 :D
About posing riddles in an interview, I prefer to present candidates with a problem we have now or have had in the past and ask them for a possible approach towards the solution. It makes much more sense.
Coditor
Admin
No double-blind bicycles??
:)
(captcha: scooter - they trying to tell us something?)
Admin
It's not that the puzzle questions are a complete waste, but that they are an inefficient use of time. If you want to test for recognition of sorting algorithms or statistical filters or whatnot, there are plenty of real world example problems that could be used.
The problem with the puzzle questions is that their real purpose is unclear, which is not useful for either side of an interview. Interviewers who use them will give a variety of breathtakingly vague answers, which ought to signal the problem, but ego+habit is a tough combo to beat. I won't/didn't just walk out on such questions, but treat it like any interview question (why are they asking? what will they do with my answer? how can I use this to my advantage?). The questions do have a sort of cultural badge associated with them, as evidenced by the number of responses here, but that could easily be tested for with Sci-fi trivia questions and have the same relevance to the profession.
I work for the company that sparked all this, and some interviewers there still do this junk. I don't, but I'd give a "hire" to the answer in the OP if I did.
Admin
Admin
Admin
I too am amazed at the huge number of very vocal people here who absolutely refuse to bother with the actual requirements when working out a solution.
What's more interesting about all this is that these brain teasers actually give a chance to weed out the kind of people who should absolutely not be hired - the ones who, even when an exhaustive simulation shows that a particular answer works, continues to "disprove" it on some theoretical (dogmatic) grounds that he or she learned in statistics class twenty years ago, applied without taking everything into account. I mean, what are mere facts in the face of Knowledge? :)
Admin
(I'm posting this for nostalgic purposes, I also suspect that some of my ex-colleagues read this site, - might see you Friday ;-)
If I have 3 pieces of bread and I want to toast them on an old-fashioned grill, what's the quickest (most efficient) way of doing so ? The grill heats from above only (I want both sides toasted) and you can only fit 2 pieces of bread on it at a time.