Sunday, November 23, 2008

Alumni adding flavour NITC

"Life After NITC"

I still have three more years here in NITC
I laughed
Why should i be thinking about it now
That was my first question.
It was me who first saw the poster as i was the one to stick it on all the notice boards here in hostel.
I dint want to spent my time listening to such bluffs.
So it was when i was going to take bath, my friend called me for the talk.
At first i was like "Oh man,Have to study, no i am not coming"
But to say the truth i would have missed a really excellent interactive session with our nitc 'pass out'
They were four of them giving their experience here and when they got out of here.
Their talk session was informative and interestiing.All of them are currently doing their mba in iim calicut.
They expressed their view on talking an mba or not and what time is suitable to take it.According to them its all one's perspective to take the rite time to do mba.
Be it anytime ,right when you passout from college or after some years of work.If one is taking mba just he get out of the college, he is still a student so its easier to him for continuing study.But for someone who is coming after some years of work ,it might be little difficult for him to get on to play.

MBA is entirely a different area of study for a btech pass out.It adds one more degree to one's resume and make an engineer capable of managing a business.though i dont know much about it.I am still doubtful of taking an mba or not.I confident that sometime during these times in Nit calicut i would reach to a conclusion

Actually i had planned to post this one month before.but due to lack of time during exams i could'nt do it

Friday, November 21, 2008

tower of hanoi recursive

#include
#include
using namespace std;
char left[20],right[20],middle[20];
void Hanoi(int n,char from[20],char to[20],char by[20]);
void print(char temp[20]) //this is to print the towers as given in the parameter
{
int size=strlen(temp);
int i=size-1;
while(i>=0) //since in this program i am storing the least value at the zeroth index it is good if the printing takes place in the reverse oreder as in the output
{
cout< i--;
}
cout<<"\n";


}
int main()
{

int n;
strcpy(::right,"\0");
strcpy(::middle,"\0");
cout<<"Enter the no of discs in the tower of hanoi (should be less than 10)\n";
cin>>n;
if (n>=10)
{
cout<<"Quiting\n";
return 0;
}
char init='1';
int i=0;
while(i {
::left[i]=init;
init++;
i++;
}
::left[i]='\0';
cout<<"Tower1: ";
print(::::left); //printing the initial state of all the towers
cout<<"Tower2: ";
print(::middle);
cout<<"Tower3: ";
print(::right);
cout<<"\n\n\n\n";
sleep(1);
Hanoi(n,::left,::right,::middle);
return 0;
}
void Hanoi(int n,char from[20],char to[20],char by[20])
{
if (n==1)
{

int size;
size=strlen(to);
int i=size+1;


while (i>0) //this is to make ready the insertion point for the element that has to be added
{
to[i]=to[i-1];
i--;
}
to[0]=from[0]; //the top most element of from will be added to the top position of to
size=strlen(from);
while(i {
from[i]=from[i+1];
i++;
}
cout<<"Tower1: ";
print(::left); //printing the present condition of all the towers
cout<<"Tower2: ";
print(::middle);
cout<<"Tower3: ";
print(::right);
cout<<"\n\n\n\n";
sleep(1);
}

else
{
Hanoi(n-1,from,by,to); //here, these are the recursive calls to the function Hanoi
Hanoi(1,from,to,by);
Hanoi(n-1,by,to,from);
}

}

permutation of letters, including repetition

#include
#include
using namespace std;
int count=0,top=0;
char tempstr[50][50],a_ll_combinations[1000][15];
int checkEquality(char variable,char checking_string[50],int end,int i);
void permutation(int n,char string[50]);
int main()
{ ::count=0;
char string[50];
cout<<"Enter the string\n";
cin>>string;
cout<<"\n\nHere is all the possible combination of string "< int n=strlen(string); //calculating the string length
if (n==1)
{
cout<<"The only possible combination is \n";
cout< }
permutation(n,string); //calling the function
int i=1;
for (int i=0;i {
cout< }
cout<<"The number of combinations printed is "<<::count<<"\n";
return 0;
}
void permutation(int n,char string[50])
{
if(n==2)
{
//setting the base case as a small string of size 2
strcpy(a_ll_combinations[::top++],string); //so in the base case two strings are generated
if (string[1]==string[0])
{
::count++;
return;
}
char temp=string[0];
string[0]=string[1];
string[1]=temp;
strcpy(a_ll_combinations[::top++],string);
::count+=2;
return;
}
for (int i=0;i {
if (i==0)
{
strcpy(tempstr[n],string); //this is for saving the string that is passed for an element being at the last position recursively,
} //so that in the next state alteration can be done with the previous one
strcpy(string,tempstr[n]);
if(checkEquality(string[i],string,n,i)==1) //here it checks whether the character which is going to be swapped was already in the nth position
continue;
char temp=string[n-1]; //here, changing the last element in each iteration
string[n-1]=string[i];
string[i]=temp;
permutation(n-1,string); //calling for the permutation of n-1 letters -recursion

}
}
int checkEquality(char variable,char checking_string[50],int n,int end) //this is the definition for the checking for duplication
{
for (int i=0;i {
if (checking_string[i]==variable)
return 1;
}
return 0;
}

Sunday, November 16, 2008

busy life.........

its been long since i posted my last post.
life here in nitc is a little busy
even if u are not doing anything u wont know how time passes
it goes unnoticed
after tathva, major work got over ,since then we were left to us
calls from the seniors got less but not for sticking posters for which i was their favourite .
in the next weekend i went home, it was after two months since my last visit to my home ,it was a wonderful moment for me the stay lasted only for two days
then back at nitc
i thought of studying everything from scratch
since then i reduced my extra carricular activites
we had to complete certain assignments
it was in pd that we got four assignments (programming ) each of them with seperate paths
the tuffest one was the tower of hanoi problem
i had the algo with me , it was then all about implementing it
day and night i only had this in mind ,surfing from one error to other and atlast i could make it working
to say frankly i was trying to crack it ever since this semester started but the only thing is that i dint put a lot of work in it ,since it was something like imposed on us through assignment ,i had to
i am giving my code for it in the next post
currently i am trying to remove the second recursive call and change it to an iterative one ,another big task for me
i am currently getting no idea about it ,but somehow i will crack it ,deadline is three days it seems as our exams are starting next week