Archive for June, 2006

About MS.NET 3.0 !

The Microsoft .NET Framework 3.0 (formerly known as WinFX), is the new managed-code programming model for Windows. It is the standard set of APIs for Windows Programming and .NET 2.0. I found this very useful artcile on use of MS.NET 3.0. Hope all enjoy readng it too.



WinFS will not be shipped seperately.

June 29, 2006 1 comment

WinFS which was initially planned to be part of Windows Vista along with Avalon ( Windows Presentation Foundation) and Indigo ( Windows Communication Foundation) as the new file system, promising new innovation and taking file system architecture to extremes will now not be shipped seperately. It will be part of SQL and ADO.NET in Orcas may be. This is a very strange news from Microsoft. WinFS was the most anticipated part of Windows Vista and was considered to be a mile stone. Any ways for further details check out the WinFS official blog site.


Categories: Computer Science

Great books for Programming Courses !

June 22, 2006 1 comment

I just came across this book "Computer Systems: A Programmer's Perspective". I had my Introduction to Programming course back in Spring 2001, and this book has reminded of those wonderful days :). What a splendid book. A must read for any one who has joined any Computer Science major course and a good reference book for all the programmers, instead it contains most of the things every programmer should know. Written by CMU Professor's, it's one of the coolest book to come across. This is the best book to start after a simple programming course, that can teach you a Computer System along with how programming is done successfully on it.

Another good book taught in MIT for those taking Introduction to Programming course is "Structure and Interpretation of Computer Programs". It is an introduction to Computer Programming book taught in MIT and it take's LISP as it's default language. One of the de-facto standard text on the subject (I wish all Universities raise the standard of programming courses to this book's level). The tag on my blogs "Dedicated to the spirit that dwells in Computer Programs" is also a modification of some text in this book. I hope one enjoy reading these 2 great books.


Programming is Important for CS-Majors !

June 20, 2006 1 comment

One of the most common miss conceptions for CS-Majors is that they can avoid Computer Programming and still remain successful in field of Computer Science. Many so called IT Professionals and hence so called successful guys claim that programming is tough, boring and a programmer’s/developer work is just tough laboring work and pays you nothing. But for me and the real guys in Computer Science, it’s all about computer programming and in broader sense problems solving with a good command on algorithms. Every time I successfully compile and execute my program it gives me an intrinsic feeling of accomplishment(worth more than any thing else). There are many CS graduates who have changed their line for the simple reason that they could not find job or they could not find enough money if they find a job or simple they are not capable enough, so they curse Computer Science and Programming. But the point is, in the first instance it’s their own fault, and secondly its fault of local industry, Computer Science has nothing to do with it. But if you are a CS-Major and you think you can avoid algorithms and programming then you are living in a fool’s paradise and you will get nothing in the longer run unless you get some non-technical easy degree like MBA and start making money by only what you speak or pretend, and don’t know any thing about inside out. I have seen many guys joining MBA and then thinking we will get a 50K+ at-least a month in start :). MBA is a cool course and I think it is necessary for people who want to manage things either you are a doctor/engineer/scientist/educationalist, but how come you can manage a Software’s Creation or a Hospital, if you have never created one or managed. Or how can you manage some industry when you have never worked in that industry. So in my view those getting CS/Engineering majors and then shifting to MBA without any experience will end up dumbing any project or product for sure. Specially like the MBA graduates(a few exceptions) we see in society whose sole aim is to lie to sell products, to deceive others, and to make use of others work and then thinking we are making good money and are successful have only an illusion of success. So CS majors, remember computer programming is every thing in Computer Science most of the times and at other times it’s not computer science.

I wrote this post a some time ago, and then I read this great article of Joel.

P.S: No hard feelings for MBA's, you just have to be more logical 😉



Categories: Computer Science, General

An interesting small programming puzzle.

June 13, 2006 26 comments

Abubakar Sultan who was my senior at NetSol and the best Microsoft.NET programmer I have seen so far in Pakistani industry, has made this programming question and asked many to solve this.

For any given n(positive integer only), you have to print integers from 1 to n and then print from n-1 to 1 using only a loop without any explicit if-else or ternary operators and not using any other memory location except loop variable.

Example: if n = 7 then out put should be 1 2 3 4 5 6 7 6 5 4 3 2 1

He claimed no one have been able to solve this in first try. However I solved this problem and come up with the follwoing solution. I am pasting the C++ source to print the same.

int n = 7 ; // set any integer value here

for( int i = 1; i  <= (2* n) ; i++)
     cout << (( i <=n) * i) + ((i > n) * (i – ( i – n ) * 2));

This is really an interesting programming puzzle and I enjoyed working on it.


Coin Denomination Problem !

June 6, 2006 14 comments

I was asked to solve the coin denomination problem in an Interview. The problem statement is: Given an amount of money, and some coins that are used in some country ( which will definitely include at-least 1 coin of worth 1), you have to find the minimum number of coins which will be used to convert the amount of money in coins. I came up with 3 solutions ( greedy algorithm which is trivial ), recursive which is tough but costly and finally a Dynamic Programming solution. I coded the algorithm in C# which is pasted below, this code will print the minimum number of coins that will be used, but the not exactly those coins which are being used in the solution, for that very purpose we have to store some addictional information, but doing that is not that much of a tough task, so enjoy the C# code

//***************** this is portion of code

int money = 9; // set any amount of money here

int [] maxcoins = new int [money + 1];

int [] coins = { 1 , 4 , 5}; // set any values here

for( int i=0; i < maxcoins.Length; i++)
    maxcoins[i] = 10000; //this value should infact be very large

maxcoins[0] = 0;

for(int i = 1; i <= money; i++)
    for( int j=0 ; j < coins.Length; j++)
         if( i >= coins[i])
           if( (maxcoins[i – coins[j]] + 1) < maxcoins[i])
             maxcoins[i] =  maxcoins[ i – coins[j]] + 1;

Console.WriteLine( maxcoins[money + 1]);

I will explain the logic later. 😉


Ouroborous Snake !

June 3, 2006 10 comments

Once I made a programming problem set for In-House programming contest and gave this problem , at my University taken from ACM. The problem statement is:

Ouroboros is a mythical snake from ancient Egypt. It has its tail in its mouth and continously devoursitself. The Ouroboros numbers are binary numbers of 2n bits that have the property of “generating” the whole set of numbers from 0 to 2n-1. The generation works as follows: given an Ouroboros number, we place its 2n bits wrapped in a circle. Then, we can take 2n groups of n bits starting each time with the next bit in the circle. Such circles are called Ouroboros circles for the number n. We will work only with the smallest Ouroboros number for each n.

Example: for n = 2, there are only four Ouroboros numbers. These are 0011, 0110, 1100 and 1001. In this case, the smallest one is 0011. Here is the Ouroboros circle for 0011:

1.jpeg                            2.jpeg

The table describes the function o(n,k) which calculates the k-th number in the Ouroboros circle of the smallest Ouroboros number of size n. This function is what your program should compute.


The input consists of several test cases. For each test case, there will be a line containing two integers n and k (1 <= n <= 8; 0 < k < 2n). The end of the input file is indicated by a line containing two zeros. Do not process that line.


For each test case, output o(n ,k) on a line by itself. 

Sample Input
2 0
2 1
3 7
4 14
0 0 

Sample Output

I recently solved this problem in my office. This costed me an exciting half an hour to solve it and code it perfectly. The real problem I faced is as soon as the size of n grows ( in terms of powers of 2), the computaion becomes too much and hence slow and solution comes too late. But the interesting part is the algorithm. Any ways interested people can solve this and I am sure this will interest them.

I, Haroon