Monday, October 20, 2008

Rabbit poupulation Fibonacci sequence

Question :
A young pair of rabbits (one of each sex) is placed on an island. A pair
of rabbits does not breed until they are 2 months old. After they are
2 months old, each pair of rabbits produces another pair each month.
Find a recurrence relation for the number of rabbits on the island
after n months, assuming that no rabbits ever die.

Solution :
Suppose there are An rabbits after n months.
Then number of rabbits born in (n+1)th month is : An+1 - An.
An+2
= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.
= 2*An + An+1 - An
= An + An+1
= Fibonacci sequence

Fibonacci sequence, rabbit population

Question :
A young pair of rabbits (one of each sex) is placed on an island. A pair
of rabbits does not breed until they are 2 months old. After they are
2 months old, each pair of rabbits produces another pair each month.
Find a recurrence relation for the number of rabbits on the island
after n months, assuming that no rabbits ever die.

Solution :
Suppose there are An rabbits after n months.
Then number of rabbits born in (n+1)th month is : An+1 - An.
An+2
= 2*number of rabbits in nth month + number of rabbits born in (n+1)th month.
= 2*An + An+1 - An
= An + An+1
= Fibonacci sequence

Thursday, October 16, 2008

0 is same as '\0'

void main(){
char check[10];
check[0] = 'a';
check[1] = 'b';
check[2] = 0;
printf("%s\n",check);
}
will produce the same output as :

void
main(){
char check[10];
check[0] = 'a';
check[1] = 'b';
check[2] = '\0';
printf("%s\n",check);
}

since ascii code of '\0' is 0,
whereas ascii code of '0' is 48.

Sunday, October 12, 2008

php dom xml problem

Problem :
Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\xyz.php on line 8.

solution :
php_domxml.dll extension has to be commented in the php.ini file under apache/bin.(or
whatever php.ini file is loaded for you, find out through phpinfo()).

source.

Wednesday, October 1, 2008

Vim : stop making a tilda/tilde file

I came across two ways to do it:
(i) :set nobackup and :set nowritebackup
but it didn't work for me.

(ii) :set backupdir=$VIMRUNTIME/vim_backup
it worked for me. Bascially create a directory, where the backup files(tilda files)
will be created. Surprisingly, the backup files are not being created here.
And nowhere else.

I am using gvim on Windows btw.

A software for theorem proving

http://isabelle.in.tum.de/

Blog Archive