Wednesday, October 26, 2005

Democracy among integers

You have a 32 bit unsigned integer. You want it to be really reliable, so you store it three times (triple redundancy). Write a subroutine that takes three unsigned, 32 bit integer arguments, and returns a single unsigned 32 bit integer that is constructed by having the bit in each bit-position "vote" for the corresponding output bit (e.g. if at least two of the low-order bits in the passed in arguments are 1, then the low-order bit in the output is a 1).

Hint: There's an easy, fast way, and there's a hard, slow way. I'm looking for the easy, fast way.

(Found on /.)

Interview questions

Starting today, I'll be posting here, puzzles for Engineers. By this, I mean, puzzles that assume knowledge of certain technical aspects. To begin with, here is a simple one:

You are writing a parser that reads a C program and translates all the variable names into new names of the form "VAR######", where ###### is an integer incremented for each unique variable name. Discuss what is needed for the case where the C program already contains a variable of the form "VAR######".
(Found on /.)

Saturday, October 22, 2005

"Para"-Trains

A helicopter drops two trains, each on parachute, onto a straight infinite railway line. There is an undefined distance between the two trains. Each faces the same direction, and upon landing, the parachute attached to each trains falls to the ground next to the train and detaches. Each train has a microchip that controls its motion. The chips are identical. There is no way for the trains to know where they are. You need to write the code in the chip to make the trains bump into each other. Each line of code takes a single clock cycle to execute.

You can use the follwing commands (and only these);
MF - moves the train forward
MB - moves the train backward
IF (P) - conditional that's satisfied if the train is next to a parachute. There is no "then" to this IF statement.
GOTO

Source: Microsoft Questions by Kiran Bondalapati

Ninja Cake Slicer

Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remaining of the cake into two equal halves with one straight cut of a knife?

Source: Microsoft Questions by Kiran Bondalapati

Wednesday, October 19, 2005

T

Form the letter 'T' from the shapes given in the figure below. (Print it and cut it so that it'll be easy)

Source: Unknown

Monday, October 17, 2005

A balancing act

You're in a dark room with 50 quarters, 18 of which are heads up. You are allowed to move around the coins or flip some or all of them, if you wish. Problem is, it's too dark to tell what you're moving or flipping (no, you can't figure it out by touch either). Your job is to split the coins into two groups, each of which has the same number of heads up coins. How do you accomplish this?

(Found on Slashdot)