Posts

To print longest pattern sequence

Problem: Write a program to print longest pattern sequence. e.g. Input String str="123424861234567"; Patterns are "1234","2486","1234567" with common difference 1,2,1 respectively.So being the longest third pattern i.e.  "1234567" is the output. package assignment1; /**  * @author snlkjha  */ public class Str {         public static void lognest_str_pattern(char s[]){                 int count1[]=new int[5],count2[]=new int[5],t=0,max=0,i,j;    // Variable declaration         for(i=0;i<s.length;i=i+j+1){             j=0;             while((i+j+1)<s.length && (s[i+j+1]-'0')-(s[i+j]-'0')==((s[i+1]-'0')-(s[i]-'0')))   j++;             count2[t]=i+j+1;             count1[t]=j+1;             max=count1[m...

How to install java in ubuntu operating system

                                            Open terminal On the command line, type: $   sudo apt-get install openjdk-7-jre ( The   openjdk-7-jre   package contains just the Java Runtime Environment. ) If you want to develop Java programs then install the   openjdk-7-jdk   package by typing : sudo apt-get install openjdk-7-jdk . 

Quick Sort Simplest Code

public class Sort {   public static void quick(int a[],int beg, int end){     if(beg<end){         int p=partition(a,beg,end);         quick(a,beg,p-1);         quick(a,p+1,end);     }   } public static int partition(int a[], int beg, int end){     int c[]=new int[a.length],l=beg,r=end,pivot=beg;    //variable declaration     for(int i=beg+1;i<=end;i++){         if(a[i]<a[pivot]) c[l++]=a[i];         else c[r--]=a[i];     }     c[l]=a[pivot];     for(int i=beg;i<=end;i++)         a[i]=c[i];        return l; } public static void main(String[] args){     int a[]={26,19,45,30,34,42,15,18,21,32,36,13,22,33,14,32,42};     int n=a.length;     System.out.println("List Before Sorting:-\n\n"); ...

Double The Size of an Image using Bi-linear Interpolation

Image
%================== Program to double the size of an Image ===================% A=imread('pic1.tif'); [M N]=size(A); B=uint8(zeros(2*M,2*N)); for i=1:M     for j=1:N         B(2*i-1,2*j-1)=A(i,j);         B(2*i,2*j-1)=A(i,j);         B(2*i-1,2*j)=A(i,j);         B(2*i,2*j)=A(i,j);     end end C=B; [M N]=size(B); mask=[0, 1, 0;1, 0, 1;0, 1, 0;]; const_mat=zeros(1,4); for i=1:M     for j=1:N         mat=zeros(1,4);         S=zeros(4,4);         m=1;         for x=1:3             for y=1:3                 if(((i+x-2)<M &&(j+y-2)<N)&&((i+x-2)>0 && (j+y-2)>0))                     if(mask(x,y))         ...

8 Bit Plane Slicing of an image in Image Processing

Image
%================ Bit Plane Slicing Program =================% A=imread('bit_plane_img.tif'); subplot(3,3,1),imshow(A),title('INPUT IMAGE'); for i=1:8     B=bitplaneslicing(A,i);     subplot(3,3,i+1),imshow(B),title(i); end %====================================================% %================ Bit Plane Slicing Function =================% function [ B ] = bitplaneslicing( A ,n) % function for n bit plane slicing where n<=8 [M,N]=size(A); B=zeros(M,N); for i = 1:M     for j = 1:N         str=dec2bin(A(i,j),8);         if strcmp(str(9-n),'0')             B(i,j)=0;         else             B(i,j)=2^(n-1);         end     end end end %====================================================% Input Image: bit_plane_img.tif Output Image:

Prisoner Dilemma Problem

Prisoner Dilemma Problem Cooperation is usually analyzed in game theory by means of a non-zero-sum game called the “Prisoner’s Dilemma”. The two players in the game can choose between two moves, either “cooperate” or “defect”. The idea is that each player gains when both cooperate, but if only one of them cooperates, the other one, who defects, will gain more. If both defect, both lose (or gain very little) but not as much as the “cheated” co-operator whose cooperation is not returned. The whole game situation and its different outcomes can be summarized by table below, where hypothetical “points” are given as an example of how the differences in result might be quantified. Payoff Matrix for Prisoner Dilemma Player 1 Player 2 Cooperate Defect Cooperate 3,3 5,0 Defect 0,5 1,1 Step1 : Initialization of 20 population each of 70 (64+6) Strings where six extra letters encode three previous...

BEST PROGRAM FOR STRING PALINDROME IN JAVA

/* The progrma will check whether a word is palindrome.  * BEST PROGRAM FOR STRIG PALINDROME IN JAVA */ package advance; import javax.swing.*; public class Palindrom {     public static boolean ispalindrom(String str) {         int i = 0, j = str.length();         while ((i < j) && (str.charAt(i++) != str.charAt(--j))) {             return false;         }         return true;     }     public static void main(String[] args) {         String str = JOptionPane.showInputDialog("Enter a string");         if(ispalindrom(str))             JOptionPane.showMessageDialog(null, str + " is a Palindrome String.");         else             JOptionPane.showMessageDialog(null, str + " is a not a Palindrome Str...