Rain expected in the crunch-game

India’s cricket match against English side is under threat from high above. It is supposed to rain and the match maybe reduced by a few overs I believe. If it was China hosting the event, they would have surely taken care of the Clouds by using some form of chemical dispensers, as they did during the Olympic games. On the other hand, India may be happy to get away with 1 point instead of a big ZERO!

The only way England is capable of winning the match is to bat first, score more than 300 and put pressure on the famed Indian batting line up otherwise, India will have England for lunch and dinner! Smile

0  

Serializing Objects in JSON format

Serializing data/objects using XML is quite a standard way over the Web. But, XML has it’s own set of disadvantages owing to which I tried serializing objects in JSON format. It seems .NET has in-built support for doing the same. One simply needs to use the JavaScriptSerializer class available within ‘System.Web.Script.Serialization’ namespace.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization; /*Add System.Web.Extension library*/

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            JavaScriptSerializer sz = new JavaScriptSerializer();

            List<Employee> empList = new List<Employee>() 
                { new Employee("gaurav", 1), 
                    new Employee("gauz", 2) };

            Console.WriteLine(sz.Serialize(empList));
            Console.ReadLine();
        }
    }

    class Employee
    {
        public string name;
        public int id;

        public Employee() { }

        public Employee(string Name, int ID)
        {
            this.id = ID;
            this.name = Name;
        }
    }
}
0  

Interesting puzzle about Apples and Numbers!

My friend asked me this question earlier today.

"Arrange n^2 apples in a square. From each row find the largest one and let A be the smallest of these. From each column find the smallest one and let B be the largest of these. Which one is bigger, A or B? Give reason."

The obvious thought which crossed my mind was to replace apples with unique numbers between 1-9 in a 3×3 matrix. Also, the question itself suggested the algorithm within itself to go about and find evaluate A & B.

Case I: My immediate matrix looked like this >>

1   3   6

2   5   9

4   7   8

By following the above mentioned steps, the least value found across the maximum from each rows was 6 while the max value found across the minimum from each column was 6 again!

Case II: But when I use the matrix such as >>

1   3   9
7   8   6
5   4   2

By following the above mentioned steps, the least value found across the maximum from each rows was 5 while the max value found across the minimum from each column was 3!

Immediately I realized that, the variation is purely because of the way we distribute numbers.

In case I, I used sorted sequence of numbers while in case II, I uniformly distributed the numbers at random. Result became fairly obvious!

0  

How the overflow arises!

I looked up scripting languages and saw the unlimited precision capability of the integer format. It immediately made me think how overflows are handled in C!

C language uses 16 bit to represent variable type int. Most significant bit is used to represent the sign  If the most significant bit is zero then the value is treated as positive, if it is 1 then negative. For example, consider the 16-bit integer number representation, which is illustrated  as follows:

Binary Number                                                   Decimal Equivalent

0000 0000 0000 0000                                                     0

0000 0000 0000 0001                                                     1

………….

0111 1111 1111 1111                                                    32,767
If I add 1 to 32,767, we would expect the result to be 32768. However, the value becomes -32,768 as follows:
1000 0000 0000 0000                                                 -32,768

 

#include <stdio.h>

void main(void)
{
    int pos = 32767;
    int neg = -32768;

    printf("%d + 1 is %d", pos, pos+1);
    printf("%d - 1 is %d", neg, neg-1);
}

Output:

32767 + 1 is -32768

-32768 – 1 is 32767

0  

Diablo 3 Pre-Orders Available Now!

Diablo III - Cover Page

The day has arrived … Diablo 3 Pre-Orders Available Now!

0