Fiddling with for statement

At times fiddling with C programs and syntax can be real fun. Following is a simple program in C, which currently is not working
#include <stdio.h>
int main(int argc, char *argv[])
{
int i, n = 20;
for ( i = 0; i < n; i--)
printf("-");
return 0;
}
You can change one character in the above program to make it working. There are three such solutions existing. So have fun with the C syntax and more than one way to accomplish task.

Black and White Heads

Mathematical Induction is one of the powerful techniques for proving a conjecture for countable infinite sets. Below is one classic example of a problem, which is solved using mathematical induction arguments. The problem is from classic book on discrete mathematics, Elements of Discrete Mathematics (Mcgraw-Hill Computer Science Series). The problem goes as follows -
The king summoned the best mathematicians in the kingdom to the palace to find out how smart they were. The king told them: "I have placed white hats on some of you and black hats on the others. You may look at, but not talk to, one another. I will leave now and will come back every hour on the hour. Every time I retur, I want those of you who have determined that you are wearing white hats to come up and tell me immediately". As it turned out, at the nth hour every one of the n mathematicians who were given white hats informed the king that she knew she was wearing a white hat. Why ?
There are several variations of the above problem but the underlying theme is same. The solution for the above problem is given in the book whose link is given above. The problem is a fantastic application of the use of mathematical induction in proving certain conjecture. In our problem, the conjecture is at nth hour all the mathematicians wearing white hats will know about it.
Such types of proofs occur commonly in the computer science and mathematics domain. In all such situations, we have a set having a certain property and we wish to prove a conjecture over the given set.

Single Pass Palindrome Determination

We are supposed to give an algorithm which would determine whether the given input string is a palindrome or not. However there are certain constraints on the algorithm. The constraints are as follows -
  • You do not know the length of the input string
  • You can read each character of the input string only once (I think that the implication of this constraint along with the previous should be clear to everyone)
  • You have to employ constant space
Now you have to come up with an algorithm and if you claim it to be the best then a proof for the same.