Thursday, November 17, 2005

A falsidical paradox

[^ represents to the power of and (d/dx) represents differentiation with respect to x]

x^2 = x + x + ... + x (x times)

=> (d/dx)(x^2) = (d/dx)(x + x + ... + x)

=> 2x = 1 + 1 + ... + 1 (x times)

=> 2x = x

Of course, this is wrong. Find the bug in the argument. Also explain why we are getting '2' particularly.

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