misc algorithmic puzzles in c/c++