   Triangle Problem Anyone seen this trick. By moving just three of the X's below anywhere, transform this triangle     x     x x   x x x x x x x x x x x x Into this: x x x x x x x x x   x x x   x x     x I guess that it can be done by moving 4 of the X's around.  Tim Saturday, September 7, 2002 Anyone seen this trick.

By moving just three of the X's below anywhere, transform this triangle from         this

X
X X
X X X
X X X X
X X X X X

To this:

X X X X X
X X X X
X X X
X X
X
Tim Saturday, September 7, 2002 Transform this triangle by moving just three X's anywhere from this form ----X ---x x --x x x -x x x x x x x x x To this: x x x x x -x x x x --x x x ---x x ----x Ignore the '-'s Tim Saturday, September 7, 2002 Tim, I'm finding it quite entertaining just watching you have fun with it! :-) Sarain H. Saturday, September 7, 2002 I know, I had some formatting problems, then decided to do HTML tags, but ya can't, I think I got the picture across, though. Tim Saturday, September 7, 2002 It takes 5 moves to flip a 5-row triangle, not 3 (or 4). You can flip a 4-row triangle in 3 moves, though. Troy King Sunday, September 8, 2002 That's what I thought.  The interviewer said that it could be done with a five row triangle.  for a four row triangle you could just rotate the edge x's by one x: ---X --x x -x x x X x x X rotate to get: X x x X -x x x --x x ---X Tim Sunday, September 8, 2002 You don't have to move any x's. Just rotate the page (or your monitor) by 90 degrees. You could interchange 3 x's while you're at it. Jared Sunday, September 8, 2002 It sounds like one of those "think outside the box" interview questions.  Maybe the intent is to weed out the Densa than Mensa candidates, but I don't think this type of question tells you jack about how the person will perform on the job. Anyway, I can't resist a puzzle, so I took a crack at it.  If you consider a pattern of x's to be one X ... XxX xXx XxX You can transform it in 2 moves. Nick Hebb Sunday, September 8, 2002 True.  It just shows how to do puzzle problems.... Tim Sunday, September 8, 2002 "but I don't think this type of question tells you jack about how the person will perform on the job." ...unless they get really pissed off and start throwing desks and smashing windows. I've blown so many interviews that way. There's something about the way those X's look at you, taunting, it just infuriating... Robin Debreuil Sunday, September 8, 2002 Yeah, I hate crap like this where the answer is to change the question. It proves nothing about coding skills. In fact, I considered Nick's "treat groups as a single X" solution, but it doesn't maintain the shape of the original triangle in reverse -- it only swaps the number of items in the rows, putting them from 5,4,3,2,1 rather than 1,2,3,4,5, and that wasn't the presented problem. If redefining the question is acceptable (which means the SPEC is incorrect ), the the solution is like so in two moves (you need to view this in a fixed-width font): 1: Move X of "1" to location shown -----x------  ----x---1-1- ----x-x-----  ---x-x---1-- ---1-1-x----  ------x-1-1- --x-1-x-x---  -x---x-x---- -x-1-1-x-x--  x-----x-x--- 2. Move X of "2" to location shown ----x---x-x-  2-2-x---x-x- ---x-x---x--  -2-x-x---x-- ------2-2-x-  2-2--x------ -x---x-2----  -x---x------ x-----2-2---  x----------- That gives final shape of: x-x-x---x-x- -x-x-x---x-- x-x--x------ -x---x------ x----------- Which is not the same as flipping the triangle from -----x------ ----x-x----- ---x-x-x---- --x-x-x-x--- -x-x-x-x-x-- to -x-x-x-x-x-- --x-x-x-x--- ---x-x-x---- ----x-x----- -----x------ which is what I took the problem to be. It's another one of those BS brain teasers that doesn't prove coding skill. In real life, I would show the rejected solution in the comments and explain why it wasn't used (to save the maintenance coder time when he thinks he finds a better solution while making some other change). Troy King Sunday, September 8, 2002 To alter what I said, I would first ask the person in charge of the spec if that were an acceptable solution rather than just rejecting it outright. My last comment assumes that changing the shape was deemed unacceptable. If it's acceptable, then voila, as Nick said. Troy King Sunday, September 8, 2002 Nick & Troy, You very very clever man. Me very impressed. Sarain H. Sunday, September 8, 2002 Recent Topics Fog Creek Home