Experiments

  1. MyIP: A Python script to know your IP Address.
  2. #!/usr/bin/env python
    
    """ A Python script to find out your IP Address
        Written By Sreejith K
        sreejithemk@gmail.com
        http://sreejithemk.net
    """
    
    import urllib2
    
    ip = urllib2.urlopen('http://whatismyip.org')
    for line in ip.readlines():
    	print '33[31m' + line + '33[0m'

    Copy this code to a file and name it myip and then move it to /usr/bin. Now it’ll be a bash command.

  3. Recursive solution for determinent of a matrix
    /*
    /*
    ############ A RECURSIVE METHOD TO FIND THE DETERMINENT OF A MATRIX ############
    ############################ WRITTEN BY SREEJITH K##############################
    ########################### http://sreejithemk.net #############################
    ########################### sreejithemk@gmail.com  #############################
    */
    
    #include <stdio.h>
    
    float input_matrix[10][10],adj_matrix[10][10],inverse[10][10] ;
    float sub[10][10] ;
    
    main()
    {
    	int i,j,order,determ = 0;
    	printf("Order: ");
    	scanf("%d",&order);
    	for (i=0;i<order;i++)
    		for (j=0;j<order;j++)
    			scanf("%f",&input_matrix[i][j]);
    	determ = determinent (input_matrix, order);
    	printf("\nDeterminent: %d\n",determ) ;
    }
    
    int pow (int a, int b)
    {
    	int i,p=1 ;
    	for (i=0;i<b;i++)
    		p=p*a;
    	return p ;
    }
    
    int determinent (float a[10][10], int order)
    {
    	int i,j,det=0 ;
    	if (order == 1) return a[0][0] ;
    	if (order == 2) return ((a[0][0] * a[1][1]) - (a[0][1] * a[1][0])) ;
    	else
    	{
    		for (i=0; i<order;i++)
    		{
    			submatrix (a, i, order) ; // To find the Submatrix of a matrix removing the ith 0th row and ith column
    			det += pow(-1,i) * a[i][0] * determinent (sub, order-1) ; // Recursively find the determinent using sub matrix
    		}
    		return det ;
    	}
    }
    
    void submatrix (float a[10][10], int column, int order) // To find the Submatrix of a matrix
    {
    	int i,j,k=0,l=0 ;
    	for (i=0;i<order;i++)
    	{
    		for (j=0;j<order;j++)
    		{
    			if (i != 0 && j != column)
    			{
    				sub[k][l] = a[i][j] ;
    				l++ ;
    			}
    		}
    		k++ ;
    	}
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s