Content feed Comments Feed

Firefox 7.0 is out : A good news to the FF-lovers

Posted by Soham Thursday, September 29, 2011

Firefox has been the favourite browser of many users like me in spite of the fastest growth of Chrome. Many users move from FF to Chrome for its speed and light-weight.
Now, as a strategy to defend that, I've seen that FF is continuously releasing new versions since end of June . Through this releases, FF has become more light-weight browser than its previous versions. Some may complain that FF is copying Chrome. but I would say what do u expect guys. Light-weighting should come in either way. So, here it's coming in FF.
Now for it's latest release, I have experienced today that FF has improved its speed a lot in it 7.0 version.

Main Features of FF 7.0 :

  • Firefox 7.0 claims to be use 20% to 30% less memory than its predecessors. That means the browser runs a lot smoothly even if many tabs are open.
  • It supports faster HTML5 animations along with many improvements to the speed of the browser.
  • It has news tools which will help developers to create faster web apps that run on Firefox.
    I'm leaving the small improvements which you can easily notice. For example, there is no "http://"-part in the address-bar now.
    Recently Chrome has had some issues with the management of resources. This also gives FF a good opportunity to come with new ideas and capture the market.
     
    I'm not very much in believing that this version will stop the growth of Chrome but certainly it'll make its current users like me, very happy.
    FF 7.0 Download Link(Windows) : http://www.mozilla.org/en-US/firefox/fx/

Linear Sorts–Counting, Radix–C Programming

Posted by Soham Tuesday, May 24, 2011

I have implemented radix and counting sorts in this program where i take inputs as the number of the numbers you want to sort and the number of digits(at max).

Then the numbers, which will be sorted, are taken as random and sorted according to the corresponding algorithm.

Take a look at the C-Code.

Radix and Counting Sort
  1. #include<stdio.h>
  2. #include<time.h>
  3. #include<stdlib.h>
  4. #include<math.h>
  5.  
  6. void count_sort(int num[],int sortd[],int no,int rng);
  7. void show(int inp[],int no);
  8. void radixsort(int a[],int n,int d);
  9.  
  10. int cnt_rdx=0,cnt_cntsrt=0;
  11.  
  12. int main()
  13. {
  14.     int no,i,digt,rng;
  15.     int *num,*cnt_srt_num;
  16.     
  17.     printf("\nHow many Numbers you want to sort:- ");
  18.     scanf("%d",&no);
  19.     printf("\nWhat is the Number of Digits(at max) in a number:- ");
  20.     scanf("%d",&digt);
  21.     rng=pow(10,digt);
  22.  
  23.     num=(int *)calloc(no,sizeof(int));
  24.     cnt_srt_num=(int *)calloc(no,sizeof(int));
  25.     srand(time(0));
  26.     for(i=0;i<no;i++)
  27.         num[i]=rand()%rng;
  28.     printf("\nThe Unsorted Numbers are:");
  29.     show(num,no);
  30.     count_sort(num,cnt_srt_num,no,pow(10,digt));
  31.     printf("\nThe Counting Sorted Numbers are:");
  32.     show(cnt_srt_num,no);
  33.     printf("Time Complexity : %d\n",cnt_rdx);
  34.     radixsort(num,no,digt);
  35.     printf("\nThe Radix Sorted Numbers are:");
  36.     show(num,no);
  37.     printf("Time Complexity : %d\n",cnt_cntsrt);
  38.     getch();
  39.     return 0;
  40. }
  41.  
  42. void count_sort(int num[],int sortd[],int no,int rng)
  43. {
  44.     int i;
  45.     int *indx_num;
  46.  
  47.     indx_num=(int *)calloc(rng,sizeof(int));
  48.     for(i=0;i<no;i++)
  49.         indx_num[num[i]]++;
  50.     for(i=1;i<rng;i++)
  51.         indx_num[i]=indx_num[i]+indx_num[i-1];
  52.     for(i=no-1;i>=0;i--)
  53.     {
  54.         cnt_rdx++;
  55.         sortd[indx_num[num[i]]-1]=num[i];
  56.         indx_num[num[i]]--;
  57.     }
  58. }
  59.  
  60. void show(int inp[],int no)
  61. {
  62.     int i;
  63.     for(i=0;i<no;i++)
  64.         printf("  %d",inp[i]);
  65.     printf("\n");
  66. }
  67.  
  68. void radixsort(int a[],int n,int d)
  69. {
  70.     int end[10],start[10],first,p,q,exp,k,i,y,j;
  71.     struct nd
  72.     {
  73.         int info;
  74.         int next;
  75.     };
  76.  
  77.     struct nd *node;
  78.     node=(struct nd *)malloc(n*sizeof(struct nd));
  79.  
  80.  
  81.     for(i=0;i<n-1;i++)
  82.  
  83.     {
  84.         node[i].info=a[i];
  85.         node[i].next=i+1;
  86.     }
  87.     node[n-1].info=a[n-1];
  88.     node[n-1].next=-1;
  89.     first=0;
  90.  
  91.     for(k=1;k<=d;k++)      //consider 3 digit number
  92.     {
  93.         for(i=0;i<10;i++)
  94.         {
  95.             start[i]=-1;
  96.             end[i]=-1;
  97.         }
  98.  
  99.     while(first!=-1)
  100.     {
  101.         cnt_cntsrt++;
  102.         p=first;
  103.         first=node[first].next;
  104.         y=node[p].info;
  105.         exp=pow(10,k-1);
  106.         j=(y/exp)%10;
  107.         q=end[j];
  108.         if(q==-1)
  109.             start[j]=p;
  110.         else
  111.             node[q].next=p;
  112.         end[j]=p;
  113.     }
  114.     for(j=0;j<10&&start[j]==-1;j++)
  115.     ;
  116.     first=start[j];
  117.     while(j<=9)
  118.     {
  119.         for(i=j+1;i<10&&start[i]==-1;i++)
  120.         ;
  121.         if(i<=9)
  122.         {
  123.             p=i;
  124.             node[end[j]].next=start[i];
  125.         }
  126.         j=i;
  127.     }
  128.     node[end[p]].next=-1;
  129. }
  130. //copy into original array
  131. for(i=0;i<n;i++)
  132. {
  133.     a[i]=node[first].info;
  134.     first=node[first].next;
  135. }
  136.  
  137. /*printf("Sorted Data:\n");
  138. for(i=0;i<n;i++)
  139.     printf("%d.  %d\n",i+1,a[i]);*/
  140. }
  141.  
  142. /*void radixsort(int a[],int n)
  143. {
  144. int i,b[MAX],m=0,exp=1;
  145. int bucket[10]={0};
  146. for(i=0;i<n;i++)
  147. {
  148. if(a[i]>m)
  149. m=a[i];
  150. }
  151.  
  152. while(m/exp>0)
  153. {
  154.  
  155. for(i=0;i<n;i++)
  156. bucket[a[i]/exp%10]++;
  157. for(i=1;i<10;i++)
  158. bucket[i]+=bucket[i-1];
  159. for(i=n-1;i>=0;i--)
  160. b[--bucket[a[i]/exp%10]]=a[i];
  161. for(i=0;i<n;i++)
  162. a[i]=b[i];
  163. exp*=10;
  164.  
  165. #ifdef SHOWPASS
  166. printf("\nPASS : ");
  167. print(a,n);
  168. #endif
  169. }
  170. }*/

Discussions will be carried out later,if needed. Any suggestions are highly solicited.

Thank You.

Problem is Magicka on Google CodeJam 2011.
I have solved it in a iterative way.

Look at it.
 
Magicka Problem - CodeJam'2011
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. char combo[36][4],opps[28][3];
  5. int c,d;
  6. char base[]="QWERASDF";
  7.  
  8. int search_combo(char buff[],char *tmp);
  9. int search_opps(char inp[]);
  10.  
  11. char* strReverse(char* str)
  12. {
  13.      int i=0,j=0;
  14.      while(str[j] != '\0')
  15.      j++;
  16.      j--;
  17.      while(i<=j)
  18.      {
  19.                  char t = str[i];
  20.                  str[i++] = str[j];
  21.                  str[j--] = t;
  22.      }
  23.      return str;
  24. }
  25.  
  26. void code_it(char inp[],char op[])
  27. {
  28.      int i,j;
  29.      op[0]='[';op[1]='\0';
  30.      for(i=0,j=1;i<strlen(inp);i++)
  31.      {
  32.           if(i) strcat(op,(char *)", ");
  33.           sprintf(op,"%s%c",op,inp[i]);
  34.      }
  35.      strcat(op,(char *)"]");
  36. }
  37.  
  38. int main()
  39. {
  40.     int t,cnt=0,n,i,j,k,l;
  41.     char elm_list[101],op[101],otpt[700],buffer[3],tmp,tm_op[101];
  42.     
  43.     //freopen("B-large-practice.in", "r", stdin);
  44.     //freopen("test.out", "w", stdout);
  45.     scanf("%d",&t);
  46.     while(t--)
  47.     {
  48.               scanf("%d",&c);
  49.               for(i=0;i<c;i++)
  50.               {
  51.                    scanf("%s",combo[i]);
  52.               }
  53.               scanf("%d",&d);
  54.               for(i=0;i<d;i++)
  55.               {
  56.                    scanf("%s",opps[i]);
  57.               }
  58.               scanf("%d %s",&n,elm_list);
  59.                             
  60.               for(i=0,j=0;i<n;i++)
  61.               {
  62.                    op[j]=elm_list[i];
  63.                    if(j>0)
  64.                    {
  65.                         buffer[0]=op[j-1];buffer[1]=op[j];buffer[2]='\0';
  66.                         if(search_combo(buffer,&tmp)==1)
  67.                              op[--j]=tmp;    
  68.                    }
  69.                    op[++j]='\0';
  70.                    if(search_opps(op)==1)
  71.                    {
  72.                         j=0;
  73.                         op[j]='\0';
  74.                    }
  75.               }
  76.               code_it(op,otpt);
  77.               printf("Case #%d: %s\n",++cnt,otpt);
  78.     }
  79. }
  80.  
  81. int search_combo(char buff[],char *tmp)
  82. {
  83.     int i,j,fl=0;
  84.     char tm[3];
  85.     tm[2]='\0';
  86.     for(i=0;i<c;i++)
  87.     {
  88.          for(j=0;j<2;j++) tm[j]=combo[i][j];
  89.          if(strcmp(tm,buff)==0||strcmp(strReverse(tm),buff)==0)
  90.          {
  91.               *tmp=combo[i][2];
  92.               fl=1;
  93.               break;
  94.          }
  95.     }
  96.     return fl;
  97. }
  98.  
  99. int search_opps(char inp[])
  100. {
  101.      int k,l,i,j,fl=0;
  102.      char tmp[100],buff[3];
  103.      buff[2]='\0';tmp[0]='\0';
  104.      for(k=0,l=0;k<strlen(inp);k++)
  105.      {
  106.           if(strchr(tmp,inp[k])==NULL)
  107.               if(strchr(base,inp[k])!=NULL)
  108.                    tmp[l++]=inp[k];
  109.           tmp[l]='\0';
  110.      }
  111.      
  112.      if(strlen(tmp)<1) return 0;
  113.      for (i=0;i<strlen(tmp)-1;i++)
  114.      {
  115.           for (j=i+1;j<strlen(tmp);j++)
  116.           {
  117.                 buff[0]=tmp[i];buff[1]=tmp[j];
  118.                 for(k=0;k<d;k++)
  119.                 {
  120.                      if(strcmp(opps[k],buff)==0||strcmp(opps[k],strReverse(buff))==0)
  121.                      {
  122.                           fl=1;
  123.                           break;
  124.                      }
  125.                 }
  126.                 if(fl==1) break;
  127.           }
  128.           if(fl==1) break;
  129.      }
  130.      return fl;
  131. }
 
It’s slightly big.I think I can reduce that.Your suggestions are highly solicited.

Discussion will be carried out if needed.

Problem is Bot Trust on Google CodeJam 2011.
I have solved the problem in C-language. The algorithm is pretty simple. If anyone want to know in details,please let me know by commenting on this post, I’ll post the details.

Here’s the C-Code:

Bot Trust Problem
    #include<stdio.h>
    #include<string.h>
    int search_pos(char seq[],int rbt,int indx)
    //Searches the next position of 'rbt' Robot
    //after 'index' in the sequence
    {
        int i,val=-1;char robot;
        if(rbt==1) robot='O'; else robot='B';
        for(i=indx;seq[i]!='\0';i++)
            if(robot==seq[i])
            {
                 val=i;
                 break;
            }
        return val;
    }
    
    int main()
    {
        int i,t,n,sq,timer,cnt=0,bt[10],inr;
        char r[10];
        int o_frst,b_frst,o_cur,b_cur,o_targt,b_targt;
        
        scanf("%d",&t);
        
        while(t--)
        {
                  timer=0,inr=0;
                  o_cur=1,b_cur=1,o_targt=1,b_targt=1;    
                  scanf("%d",&n);
                  for(i=0;i<n;i++)
                  {
                       scanf(" %c %d",&r[i],&bt[i]);
                  }
                  
                  r[i]='\0';bt[i]='\0';
                  o_frst=search_pos(r,1,0);
                  b_frst=search_pos(r,2,0);
                  if(o_frst!=-1) o_targt=bt[o_frst];
                  if(b_frst!=-1) b_targt=bt[b_frst];
                  
                  for(sq=0;sq<strlen(r);)
                  {
                       //For Orange Robot
                       if(o_targt>o_cur)
                            o_cur++;
                       else if(o_targt<o_cur)
                            o_cur--;
                       else if(o_targt==o_cur)
                       {
                                 if(r[sq]!='B')
                                 {
                                      o_targt=bt[search_pos(r,1,sq+1)];
                                      inr=1;
                                 }
                       }
                       //For Blue Robot
                       if(b_targt>b_cur)
                            b_cur++;
                       else if(b_targt<b_cur)
                            b_cur--;
                       else if(b_targt==b_cur)
                       {
                                 if(r[sq]!='O')
                                 {
                                      b_targt=bt[search_pos(r,2,sq+1)];
                                      inr=1;
                                 }
                       } 
                       timer++; 
                       
                       if(inr) sq++;//checking if the current button is pushed or not
                       inr=0;                          
                  }
                  printf("Case #%d: %d\n",++cnt,timer);
        }
        getchar();
    }
Thank you.

    Saddle Point Algorithm Clarification

    Posted by Soham Sunday, October 10, 2010

    Now we will broadly discuss the Algorithm and C-code.

    What is Saddle Point of a Matrix?
    Saddle Point in a Matrix is the point which has the highest value in the respective row and lowest value in the respective column or vice-versa( i.e Lowest in a row and highest in a column).

    The code here first takes the Matrix as input.Then shows the matrix to the user.

    Then it evaluates the saddle points.

    Evaluation:

    First we evaluate the maximum and minimum of a row. If they are not equal that means they may be a candidate for a saddle point. But if they are equal that means all the elements in that row are equal. So we don’t consider them as a candidate for a saddle point. “eq” variable is used in this case for checking equality.

    Let’s say they are not equal. Then we take maximum of each column and checks with the Minimum element of the row that was evaluated above.If they are the same, then that is shown as a saddle point.

    Same case is taken for Maximum in a row and minimum in a column.

    “cnt” variable is used to count the number of saddle points in the matrix.If the variable is 0 then there are no saddle points.

    Function Definition:

    rw(r,dec)

    Here “r” stands for corresponding row. The “dec” variable is used to indicate if we are evaluating maximum or minimum. If dec=0,then we are claiming for minimum and if dec=1, then we are claiming for maximum.

    col(r,dec)

    Here “r” stands for corresponding column.The “dec” variable is used just as rw(r,dec) function.

    Further Clarification:

    For further detailing,please let me know through your comments.

    The actual Code is here.Click here.

    Fibonacci Series Time Comparison for Recursive Algorithm

    Posted by Soham Friday, October 1, 2010

    This Program-code finds the time required to find the nth Fibonacci no. using recursive algorithm.

    This program takes no input and outputs .xls file in which the nth Fibonacci no. with the time to compute that is written

    Fibonacci no. with Recursion
    1. #include<stdio.h>
    2. #include<time.h>
    3.  
    4. int fibonacci(int i);
    5.  
    6. int main()
    7. {
    8. time_t t1,t2;
    9. int i,no,fib;
    10. FILE *fp;
    11.  
    12. fp=fopen("fibo.xls","w");
    13. if(fp==NULL)
    14. {
    15.     printf("ERROR IN FILE OPENNING\n");
    16.     exit(1);
    17. }
    18.  
    19.   
    20. fprintf(fp,"No\tFibonacci\ttime\n");
    21. for(i=1;i<=40;i++)
    22. {
    23.     fprintf(fp,"%d\t",i);
    24.     (void) time(&t1);
    25.     fprintf(fp,"%d",fibonacci(i));
    26.     (void) time(&t2);
    27.     fprintf(fp,"\t%ld\n",(long)(t2-t1));
    28. }
    29. printf("fibo.xls file has been created.\n");
    30. getch();
    31. return 0;
    32. }
    33.  
    34. int fibonacci(int i)
    35. {
    36. int x;
    37. if(i==1)
    38. return 0;
    39. else if(i==2)
    40. return 1;
    41. else
    42. {
    43.   x=fibonacci(i-1)+fibonacci(i-2);
    44.   return x;
    45. }
    46. }

    You can take a look to the xls file I’ve got in my Laptop.

     

    For further details contact me.

    SyntaxHighlighter

    E-Mail Subscription

    Enter your email address:

    Subscribe & get Regular E-Mail Updates From Codes-N-Tricks.
    Delivered by FeedBurner

    Share with Orkut

    Loading

    Recent Posts

    About Us